Sarfraz Ahmed struck a defiant century before Pakistan's spinners wrecked New Zealand's top and middle order to leave the second Test in Dubai nicely poised on Thursday.
New Zealand had reduced Pakistan to 287 for eight and appeared on course for a healthy first innings lead, but Sarfraz (112) added 81 runs for the last wicket with Rahat Ali to dash their hopes.
By the time New Zealand got the better of Sarfraz's grit, Pakistan posted 393 runs, finishing 10 behind New Zealand in their first innings.
Batting a second time, New Zealand suffered a top order collapse and finished day four on 167 for six.
The Kiwis have an overall lead of 177, and Ross Taylor (77) and the scoreless Mark Craig will return on Friday to stretch it and set Pakistan a difficult target.
Brendon McCullum (45) gave New Zealand a breezy start in the second innings before Yasir Shah and spin partner Zulfiqar Babar took over claiming three wickets apiece.
Leg-spinner Shah drew first blood dismissing the in-form Tom Latham for nine and left-arm spinner Babar dismissed Kane Williamson and McCullum to peg back the Kiwis.
Corey Anderson, Jimmy Neesham and BJ Watling also succumbed to spin and only Taylor looked confident against the slow bowlers.
It was quite different from the way New Zealand began the day with Tim Southee's double strike reducing Pakistan, who resumed on 281 for six, to 287 for eight in the morning session.
Realising he was running out of partners, Sarfraz accelerated, hitting two fours in a Trent Boult over and was undaunted even after losing Babar at the other end.
Sarfraz hit off-spinner Mark Craig for three boundaries in an over and meted out the same treatment to leg-spinner Ish Sodhi in the next over to storm into the 90s.
The wicketkeeper-batsman cut Southee past gully for a boundary to register his third Test century and broke into an animated celebration which ended with the batsman kissing the turf.
Sarfraz's patient 195-ball knock, which included 16 boundaries, came to an end two overs after the lunch break when he offered a return catch to McCullum. It was the Kiwi skipper's first Test wicket as a bowler.
Pakistan lead 1-0 in the three-Test series.