New Zealand has conjured up a remarkable victory for the second time in two weeks by chasing down a target of 285 on the final ball of a rain-shortened day five to beat Sri Lanka by two wickets in the first Test in Christchurch.

The win — coming on the back of the one-run victory over England after following on in Wellington — put the Black Caps 1-0 up in the two-match series and ended Sri Lanka’s hopes of playing in the World Test Championship (WTC) final.

Sri Lanka’s loss means India qualifies to play Australia in the final at The Oval in London, beginning on June 7.

In Christchurch, Kane Williamson played the leading role by notching up his 27th Test century in a beautifully controlled innings of 121 not out after more than four hours of play at Hagley Oval had been washed out by rain.

Loading Twitter content

The winning run came when the former captain and the injured Neil Wagner ran a bye, with Williamson securing the victory by diving full length to get his bat down in the crease before a direct hit broke the stumps.

A video review confirmed Williamson had made his ground by just centimetres.

Sri Lanka needed to win the series in New Zealand 2-0 and rely on India not winning its fourth and final Test against Australia in Ahmedabad.

Australia secured its place in the WTC final by defeating India by nine wickets in the third Test in Indore.

The Black Caps went into the final day in Christchurch on 1-28 needing 257 more runs for victory and after the rain finally cleared, they were allowed 52 overs in one extended session to achieve the task.

First-innings century maker Daryl Mitchell contributed 81 to a stand of 142 with Williamson for the fourth wicket that put victory within grasp but there were plenty of nervous moments before the win was finally secured.

At 6-270, the Black Caps needed 15 runs from the last two overs, and local nerves intensified when captain Tim Southee (1) holed out in the deep and Matt Henry (4) was run out.

Williamson kept his own nerve and clubbed a four off the fourth ball of the final over but Asitha Fernando’s last two deliveries were short and high, giving the batters no option but to go for an undignified scramble to secure victory.

The second Test between New Zealand and Sri Lanka starts at Wellington’s Basin Reserve on Friday.