Sri Lanka 294 (Karunaratne 84, Chandimal 83) and 109 for 3 (Mendis 46, Chandimal 31*) need 296 runs to beat New Zealand 431 (Guptill 156, Williamson 88, McCullum 75, Pradeep 4-112) and 267 for 3 dec (Latham 109*, Williamson 71)
Scorecard and ball-by-ball details
For the second time in the Test, Sri Lanka's inexperienced batting line-up offered more resistance than expected, but New Zealand's persistent fast bowlers supported by the safe gloves of BJ Watling ensured the home side made strides towards victory despite a bad-weather day in Dunedin. Rain and hail halted play three times at University Oval, and at stumps Sri Lanka had seven wickets left and 296 runs to get, with a better forecast for the final day.
Brendon McCullum had given his attack 405 to defend and a little more than five sessions to dismiss Sri Lanka by declaring New Zealand's second innings on 267 for 3 half an hour before lunch on the fourth day. The highlights of their quick run accumulation - 96 in 17.4 overs- was Tom Latham's third Test hundred and McCullum's record-equalling 100th six.
New Zealand's bowlers had to toil harder for wickets than their batsmen had done for runs. Play was halted either side of lunch soon after Sri Lanka began their chase but the openers' approach was not affected. Dimuth Karunaratne and Kusal Mendis batted with more confidence than they had done at the start of the first innings.
Their partnership could have ended on 28, though, but Martin Guptill dropped a straightforward chance off Mendis at first slip, leaving the bowler Doug Bracewell in anguish. In Bracewell's last over, Mendis had played a perfect straight drive and then was beaten on an expansive cover drive. Having been dropped on 13, Mendis had another reprieve on 25, when Watling could not catch a tough chance down the leg side off a gloved sweep against Mitchell Santner. Mendis collected two fours off the left-arm spinner, punishing long-hops to the leg-side boundary.
Like in his first innings, Karunaratne was dismissed against the run of play, when he tried to upper-cut Southee but edged to Watling. McCullum had held Neil Wagner back until the 29th over, and the left-arm quick broke through in his third. Udara Jayasundera ended a poor debut by fending a short ball off his ribs to Watling. Sri Lanka had gone from 54 for 0 to 64 for 2.
Dinesh Chandimal took his chances against Wagner after tea, slashing and driving outside the off stump. He middle some balls, was beaten on others, and edged a couple over the cordon. Wagner countered by targeting the body with a short-pitched attack from around the wicket, forcing defence from Chandimal.
Mendis took fewer risks, his attacking drives through cover and past Bracewell involving straight bats, as he approached his maiden half-century. He did not get there, though. Three balls after surviving a run-out chance, Mendis pushed at an outswinger from Southee that pitched on a perfect length and moved just enough to draw the edge. Watling took his ninth catch, and moved within two of the record for most dismissals in a Test. It began to rain and hail immediately after the wicket, bringing an early end to the day.
Play had begun under sunny skies on the fourth day, with New Zealand ahead by 308 and two batsmen approaching milestones. Kane Williamson got to his half-century off the second ball of the day, dabbing to square leg and sprinting the second, an indication of the urgency with which New Zealand would bat against little pressure from Sri Lanka.
Latham was playing at balls wide outside off, looking to score swiftly, and on 73 he edged Nunwan Pradeep between the wicketkeeper and first slip. It was Chandimal's catch but he did not move. Latham drove frequently through cover but a lot of his shots found fielders. Then he found the gap at extra cover off Suranga Lakmal to move into the 90s and pulled Pradeep to the long-leg boundary.
Williamson fell before Latham got to his hundred. He had lofted Pradeep to the midwicket boundary, and charged and hit Jayasundera in the same direction, but when he attempted the shot off Dushmantha Chameera, the ball nipped in, hit his pad and bowled him. Williamson's partnership of 141 with Latham had come at 4.36 an over.
Ross Taylor glanced his second ball, from Chameera, for four and hit two more boundaries in his next eight deliveries as New Zealand sped ahead. Latham drove Rangana Herath through midwicket and celebrated a Test hundred for the first time since November 2014, ending a run of seven double-figure scores without making more than 50.
After Taylor was bowled, aiming to hit Herath to deep midwicket, McCullum charged at his first ball and smashed it over the straight boundary. Five balls later, he swiped Herath over deep midwicket to equal Adam Gilchrist's record for most sixes in Test cricket, but decided he did not have to break it in this innings and declared.
George Binoy is an assistant editor at ESPNcricinfo