From 158 for 1 at tea on the final day to 230 all out.

From 131 for 0 to 230 all out.

10 wickets for 99 runs with hours left in the match.

Now, that's what you call an almighty collapse.

New Zealand took nine wickets in a dramatic final session of the second Test against Pakistan to win by 130 runs in Hamilton on Tuesday and sweep the series 2-0.

It was New Zealand's first series win over Pakistan since 1985 and a relieved captain Kane Williamson called it one of the most remarkable Test finishes he had ever played in.

"Without a doubt," he said, admitting he felt Pakistan had a chance to win when they started the final session needing 211 off 204 balls.

"You take nine wickets in a session, they're all pretty big moments... from the feeling at tea time to the feeling now is pretty contrasting and will go down as a great Test victory."

And with that, Pakistan set a new record in Test cricket.

Pakistan were faced with an imposing 369-run target but set themselves up for a run-a-ball slog when they reached tea on the final day at 158 for 1.

At that stage Williamson began to question whether he had declared New Zealand's second innings too early at 313 for 5.

"It does cross your mind, but at the point of declaration we did know that the opposition needs a sniff," he said. "They tried to chase it and we were able to get opportunities."

Pakistan captain Azhar Ali said they tried to pull out of the chase and play for a draw when Sarfraz Ahmed was run out to make it 199 for 4 but they could not hold on.

The match edged towards a cliff-hanger finish before Tim Southee removed Pakistan's leading run scorer Sami Aslam for 91.

That started the collapse which saw eight wickets fall for 49 in 20 overs with Neil Wagner taking the final three for no runs in just six deliveries.

AFP

New Zealand's series win means Pakistan fall from second to fourth in the world rankings while New Zealand move up to sixth.

Reaching 369 would have meant overtaking the record fourth innings chase in New Zealand of 348 for 5 by the West Indies 47 years ago in Auckland.