A 163-run partnership from Kane Williamson and Ross Taylor has guided New Zealand to an unlikely and record breaking Test victory against Bangladesh at the Basin Reserve in Wellington.
Williamson ended the day with 104 not-out off 90 balls.
Taylor was caught out for 60 when the team had just 15 runs left to get, but his replacement, Henry Nicholls, rotated the strike and scored four not-out to see the team through to the win.
The Black Caps are the first team in history to win a test after conceding 595 runs in the first innings, while Bangladesh now have the unwanted record for the highest first-innings by a losing team.
New Zealand needed just 217 runs to win in one and a half sessions of cricket on the final day, after Bangladesh collapsed at the hands of the hosts bowlers.
Opener Jeet Raval was the first wicket to fall in the final innings, caught and bowled by Mehedi Hasan Miraz for 13.
Tom Latham, who scored 177 in New Zealand's first innings, followed him to the sheds in the next over for 16, after playing a straight Shakib Al Hasan delivery onto his wicket.
But Williamson and Taylor steadied the innings, making the run chase look easy as they put on 163 runs for the third wicket.
After a rain-delayed first day and a mammoth 595 stand from Bangladesh in their first innings, a result in the match looked unlikely.
But on the fifth and final day, resuming at 66 for three and with a lead of 122 runs, Bangladesh looked a shadow of the team that posted a record total in their first innings.
The visitors only managed to reach 160 runs before they ran out of batsmen 45 minutes after lunch.
Captain Mushfiqur Rahim, who retired hurt in the morning session after a blow to the helmet, was still in hospital undergoing checks as his team collapsed, leaving the injured opener Imrul Kayes stranded at the crease on 36 not-out.
The Black Caps had resumed bowling on day five knowing a win, loss and draw were all viable outcomes from the match.
The home side struck early, with Bangladesh's first innings star, Shakib Al Hasan, gifting an easy catch to Williamson at mid off the bowling of Mitchell Santner.
Shakib's duck was a far cry from his record-breaking first innings knock of 217, and it wasn't long before Mominul Haque joined him in the sheds, nicking it to Colin de Grandhomme at gully while on 23 to hand Neil Wagner his sixth wicket of the match.
Just as Mushfiqur - who suffered a hand injury while batting during the first innings - looked to have settled at the crease, he was hit by a short ball from Tim Southee on the helmet.
Mushfiqur had attempted to duck, but misjudged the ball's pace.
Medical staff assessed the batsman on the ground before he was taken from the field in an ambulance and straight to hospital.
A neck scan later cleared Mushfiqur of any damage.
Taskin Ahmed replaced his captain at the crease, but managed to add just five runs to the visitors' total before he was bowled by Trent Boult shortly before lunch.
Bangladesh resumed at 137 for six after lunch and shortly after the break Sabbir Rahman scored his half century - adding to the 54 not-out he scored in the first innings.
But the wickets began to fall quickly from the next over, with Kamrul Islam Rabbi caught in the gully by de Grandhomme off Southee's bowling for just one run.
The loss of his wicket saw the return of Imrul, who retired hurt on Sunday afternoon with a thigh injury, to the crease.
But it was clear after his first shot he would not be in any position to run, limping to the middle of the pitch as the ball raced away for four runs.
Boult was rewarded next, taking the prized scalp of Sabbir when he swung at a wider ball, edging it to Watling behind the stumps to leave the ground for 50.
Bowler Subashis Roy lasted just two overs in the middle before he was clean bowled by Boult for a duck.
With Mushfiqur still in hospital, Bangladesh's second innings came to an end at 160 for nine, setting the Black Caps a total of 217 runs to win.
The second and final Test will begin in Christchurch on Friday.