The final decision is given and the Black Caps clinch victory over Pakistan by four runs in the first test.

Remarkable finish. Remarkable test match. And New Zealand, somehow, got up for one of their best comeback victories in recent memory.

Yes, the Black Caps won it. They beat Pakistan by four runs in the first test in Abu Dhabi on Monday amid a madcap collapse from the hosts who were cruising at 130-3 in pursuit of 176 to win.

It bordered on comical, a shocking mix-up run out of Babar Azam and awful wild swings from tailenders Bilal Asif and Hasan Ali among the carnage caused by New Zealand pressure.

YASIR NISAR/PHOTOSPORT On test debut Ajaz Patel took 5-59 to spur New Zealand to a stunning victory over Pakistan in Abu Dhabi.

They lost 7-41 as left-armers Ajaz Patel and Neil Wagner were Black Caps skipper Kane Williamson's go-to duo at the end.

READ MORE:

* Black Caps in the record books with win

* Black Caps 'holy scccchmoly' - world reacts

* Williamson: Test win 'one of our best'

* Meet NZ's first test hero: Ajaz Patel

* Scoreboard: Black Caps v Pakistan

* Recap: Black Caps v Pakistan

KAMRAN JEBREILI/AP New Zealand's players grab the stumps and digest a remarkable test victory, with man of the match Ajaz Patel second from right.

On test debut at age 30, Patel was New Zealand's star, calm and composed as he bamboozled the Pakistan batsmen with his spin to take 5-59 off 23.4 overs.

He ended it by trapping Pakistan topscorer Azhar Ali lbw for 65, to dismiss them for 171. Azhar carried his team to the brink and reviewed the decision but replays confirmed Patel's five-bag and sparked jubilant scenes.

Wagner bowled 13 overs on the trot and ended with 2-27, a perfect foil for the spinner.

YASIR NISAR/PHOTOSPORT A fired up Neil Wagner was the perfect foil for Ajaz Patel as the tension mounted.

Coach Gary Stead, in his first test in charge, jumped up and down like a five-year-old and punched the air as players and support staff embraced.

"It's a dream come true, debuting for New Zealand and being in a position to win the game for your country. It's a very special feeling and it's the New Zealand way to believe anything is possible. True character from us," Patel said.

It was the second-smallest target successfully defended by New Zealand to win a test, after the 137 England couldn't reach in Wellington in 1978.

For drama and tension it was up with Hobart in 2011 when Australia were set 241 and it got to single figures as David Warner ran out of partners and Doug Bracewell finished the job for New Zealand.

Heading into day four a Pakistan win was at microscopic odds at 37-0 needing another 139, albeit at a venue where the side batting last had won just one of 11 previous tests.

New Zealand needed a spark and Patel and Ish Sodhi provided it, snaring three wickets in eight balls barely half an hour into the day's play.

YASIR NISAR/PHOTOSPORT Azhar Ali was last man out for 65, having got Pakistan to the brink of victory with wickets tumbling.

It was scarcely believable as Patel turned one and thudded into Imam-ul-Haq's pads.

Then Sodhi, who was a mixed bag with his lengths, struck twice in four balls when Mohammad Hafeez chipped a soft catch to cover then Haris Sohail smacked a full toss back to Sodhi's clutches just above the turf.

Azhar and Asad Shafiq added 82 and Pakistan were well on their way.

It all turned when Wagner enticed an edge from Shafiq, then the run out saw Azhar and Babar at the same end as Sodhi fired the ball to Patel who whipped the bails off and uprooted the stump just to be safe.

Pakistan skipper Sarfraz Ahmed was given out caught off his glove and it became a game of chess as New Zealand circled and Azhar tried to protect his tailenders.

In the end they self-destructed bar No 11 Mohammad Abbas who stood valiantly as the target ticked down.

It was New Zealand's second successive test win in the UAE after Sharjah in 2014 and they're in the box seat in the series heading to Dubai for the second test on Saturday.

* Leave comments below and join the Cricket Stuff conversation on Facebook.