Angelo Mathews' resilience could not deny New Zealand their first test victory in Sri Lanka in 14 years as the visitors won the second test by 167 runs to level the two-match series on Thursday.
Mathews struck a defiant 84 and resisted the New Zealand attack before being the last man out as Sri Lanka, resuming on 47 for four, folded for 195 runs 25 minutes after tea.
The victory also ended New Zealand's five-match losing streak, their worst in 57 years.
"It was good to win after losing so comprehensively in Galle," New Zealand skipper Ross Taylor said, referring to his team's 10-wicket defeat inside three days in the first test.
"We got a lot of stick in the week leading up to this match but we were very determined to get a competitive total.
"Test match wins away from home don't happen very often, so we will enjoy this and hopefully get some momentum going forward," he said.
His Sri Lankan counterpart Mahela Jayawardene blamed the top order batsmen for the defeat.
"We lost wickets up front and so the momentum was not there. Credit to New Zealand as they bowled well throughout the series with the new ball," he said.
Sri Lanka slipped to 63 for five soon after the resumption on the final day when Thilan Samaraweera (seven) was run out after a horrible mix-up with Mathews.
Vice-captain Mathews batted for exactly five hours before being caught at second slip by Martin Guptill off the bowling of left-arm fast bowler Trent Boult (three for 33).
Mathews hit 11 fours and an on-driven six off Jetan Patel's off-spin and faced 228 deliveries.
Mathews and Prasanna Jayawardene (29) resisted together for 35 overs before Jayawardene became leg-spinner Todd Astle's first wicket at the highest level.
Suraj Randiv, who resisted for three hours in the first innings on his way to a test-best score of 39, failed to score in the second, edging Boult to Guptill at second slip.
Sri Lanka were still fighting at tea as Mathews and Nuwan Kulasekara (18) resisted for an hour up to the final interval but the end came quickly after that break, aided by the second new ball.
Kulasekera fell in the first over of the final session, caught by Kane Williamson in the gully off Boult.
In the next over, Tim Southee (three for 58) removed the scoreless Shaminda Eranga for his eighth wicket of the match when Williamson took a brilliant low, right-handed catch, his fifth of the match.
"Tim Southee and Trent Boult led the attack throughout the whole series, they were very consistent and we fed off them," said Taylor.
Taylor was adjudged player of the match for his knocks of 142 and 74, while Herath was named player of the series after taking 20 wickets, including 11 in Galle.