Jack Leach took three wickets in six balls as Pakistan slid to 99 for three at lunch on the third day in Karachi.
Pakistan started the morning on 21 without loss and looked to move the scoring on quickly, with a four off the first ball and 12 from the opening over from Joe Root.
The hosts finished the first session 49 runs ahead after England held a 50-run lead following the first innings.
Openers Shan Masood and Abdullah Shafique brought up a half-century stand before Leach’s flurry of wickets.
Masood was the first to go, bowled when attempting to reverse sweep the spinner to depart for 24.
That brought Azhar Ali to the crease for his final innings in Test cricket, but it was a heartbreaking moment for the 37-year-old.
He departed after just four balls, bowled by a beauty from his former Somerset team-mate Leach for a duck, and left the field to a guard of honour from his side.
Leach was on a hat-trick when he had Shafique trapped lbw for 26 and Pakistan had slipped from 53 without loss to 54 for three.
Saud Shakeel survived the hat-trick ball and Pakistan made England work harder for further success, with Shakeel and captain Babar Azam going into the lunch break unbeaten.