Sri Lanka scrape through in thrilling chase