New Zealand 373 (Mitchell 102, Henry 72, Asitha 4-85) and 285 for 8 (Williamson 121*, Mitchell 81, Asitha 3-63) beat Sri Lanka 355 (Mendis 87, Karunaratne 50, Southee 5-64, Henry 4-80) and 302 (Mathews 115, Tickner 4-100) by two wickets
Christchurch: Kane Williamson hit a sublime unbeaten century to lead New Zealand to a thrilling two-wicket win over Sri Lanka off the final ball of the first Test.
Williamson's 121 not out saw the Black Caps chase down 285 on a rain-shortened fifth day in Christchurch.
The hosts needed eight off the final over and scrambled a bye from the last ball to seal a dramatic win.
Defeat ended Sri Lanka's hopes of reaching the World Test Championship final in June.
Sri Lanka needed to sweep New Zealand 2-0 in this series to qualify, so India will now face Australia in the final at The Oval.
The fourth and final Test between the two sides in Ahmedabad finished in a draw, ensuring India won the series 2-1.
The Black Caps started the final day on 28-1, requiring 257 more runs for victory.
After the first two sessions were washed out, the umpires ruled there would be a maximum of 52 overs bowled in an extended final session, meaning New Zealand had to score at nearly five runs per over.
They slipped to 90-3 before Williamson combined with Daryl Mitchell for a 142-run stand off 157 balls, with Sri Lanka left to rue wicketkeeper Niroshan Dickwella dropping Williamson on 33.
New Zealand wobbled after Mitchell was bowled for 81 by Asitha Fernando, who then also removed Tom Blundell and Michael Bracewell. It left the hosts on 266-6, needing a further 19 runs with 16 balls remaining.
Captain Tim Southee also fell, but Williamson managed to take the match to the final over.
Matt Henry was run out attempting a second run off the third ball, bringing an injured Neil Wagner to the crease. The fast bowler has a bulging disc in his back and a torn right hamstring and has been ruled out of the second Test.
Williamson sliced the next delivery through point for four to level the scores before Fernando bowled a bouncer that was close to being called wide on height but was ruled a dot ball.
With one needed from the last ball, New Zealand ran a bye through to the keeper after Williamson's missed pull shot and he just managed to slide his bat down in time despite a direct hit at the non-striker's end.