Azhar Ali and Asad Shafiq hit centuries to leave Pakistan in command of the third and final Test against New Zealand in Abu Dhabi despite a batting collapse that curtailed their first-innings lead.
Azhar hit an attractive 134 for his 15th Test hundred while Shafiq scored 104, but debutant New Zealand off-spinner Will Somerville took four wickets to restrict Pakistan to 348 all out.
New Zealand were then reduced to 26-2 at stumps with Kane Williamson unbeaten on 14 and nightwatchman Somerville on one not out to leave them trailing by 48 runs with eight wickets intact.
Pakistan appeared set to build a huge lead before collapsing from 286-3 to lose their final seven wickets for the addition of just 62 runs.
Azhar and Shafiq put on 201 for the fourth wicket, but once they were dismissed only Sarfraz Ahmed (25) and Babar Azam (14) offered some resistance.
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.
That gave Pakistan a 74-run lead - the same advantage they held in the first Test at the same venue before losing by four runs.
New Zealand's second innings began poorly as paceman Shaheen Shah Afridi trapped Jeet Raval for nought while leg-spinner Yasir Shah had Tom Latham caught 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.