Pakistan middle-order batsmen Azhar Ali and Asad Shafiq hit centuries to push Pakistan into a 74-run lead despite a batting collapse on the third day of third and final Test against New Zealand in Abu Dhabi.
Azhar hit 134, his 15th Test ton, while Shafiq scored 104, but debutant New Zealand off-spinner Will Somerville took four wickets to restrict Pakistan to 348 all out.
Pakistan appeared set to build a huge lead before Azhar and Shafiq departed in quick succession, sparking a collapse as the home side lost final seven wickets for just 62 runs.
The 34-year-old Somerville finished with 4-75 while Ajaz Patel and Trent Boult returned with 2-100 and 2-66 respectively.
The 74-run lead is the same Pakistan got in the first Test at the same venue two weeks ago before losing the game by four runs.
New Zealand were then reduced to 26-2 at stumps with Kane Williamson unbeaten on 14 and night-watchman Somerville on one not out to leave them trailing by 48 runs with eight wickets intact.
Shaheen Shah Afridi trapped Jeet Raval for nought while Yasir Shah had Tom Latham caught at deep midwicket for ten, his 199th wicket in Tests.
Yasir needs just one more wicket to become the fastest to 200 wickets, in his 33rd Test, a record currently held by Australian leg-spinner Clarrie Grimmett who reached the milestone in 36 Tests, 82 years ago.
Earlier, Azhar and Shafiq frustrated New Zealand's search for early wickets as they took Pakistan to 224-3 at lunch.
Azhar edged medium pacer Colin de Grandhomme through the slips to complete his first century since May 2017 against the West Indies in Dominica - and his first hundred against New Zealand.
He took 210 balls to reach the three-figure mark, before being caught sweeping off Somerville, just before tea.
Shafiq brought up his 12th Test ton with a sharp single off Somerville before falling leg-before to Patel to a straight delivery.
Somerville then had Azam and Hasan Ali (nought) bowled and wrapped up the innings by getting Sarfraz caught at mid-wicket.