Azhar Ali and Asad Shafiq had seemingly paved the way for massive first-innings lead in response to New Zealand's 274, the two making the visitors toil for close to two sessions, but Somerville's off-spin helped spark a collapse which kept Pakistan's advantage to just 74. In response, New Zealand got to stumps at 26/2, still 48 behind.
Azhar and Shafiq had joined hands at a precarious 81/3 on the second day in response to New Zealand's 274, and had taken Pakistan's score to 139, batting with grit and resolve.
They came out with similar intent on the third day and kept each other company until Pakistan had surpassed New Zealand's total. Azhar, who began the day at 62, looked more assured at the crease, scoring with a tad more ease than Shafiq, who resumed the day on 26.
The pair made New Zealand toil the entire first session and then faced the second new ball with relative ease. Azhar went past his ton in the first session and continued to motor on until late in the second session until a top-edged sweep shot off William Somerville saw him caught at backward square leg for 134, by which point Pakistan had already gone ahead by 12 runs.
Shafiq looked less assured and enjoyed the benefit of a couple of edges falling safe and running off to the third man fence. He also had some nervy moments on 99, and soon after reaching century, he was dismissed leg-before by Ajaz Patel, playing for the turn when there was none.
The wickets of the two paved way for New Zealand to claw their way back – debutant Somerville roaring to life with his off-spin, his wickets including Babar Azam and Sarfraz Ahmed.
Azam was bowled for 14 as he got an inside edge onto the boot, the ball then deflecting onto the stumps. Skipper Sarfraz tried to keep things alive but lost partners at the other end.
Bilal Asif nicked one to slip off Patel when trying to play an expansive drive against the left-arm spinner's turn. Yasir Shah stuck it out for 25 deliveries before getting run out, and Hasan Ali got castled second ball by Somerville.
Under pressure to try and swell the advantage to something more substantial after that stellar effort by the two centurions, Sarfraz got out in the most tame manner, chipping one straight into the hands of short mid-wicket for 25, giving Somerville his fourth scalp.
Pakistan's bowlers looked potent with the new ball getting it to swing and nip. Jeet Raval got an in-dipping beauty from Shaheen Afridi to get out for a fifteen-ball duck even if the decision was a tad debatable. He was adjudged out on the field and he sent it up. Replays showed that he may have got an inside edge at the same time the ball struck his pad, but the third umpire went with the on-field umpire's call.
Tom Latham continued to struggle against Yasir Shah's big leg-breaks and perished for 10 when he miscued a sweep shot to deep square leg, leaving New Zealand in more trouble. Kane Williamson and night-watchman Somerville played out the last few overs without further damage though.