Lunch Pakistan 304 and 99 for 3 (Shakeel 28*, Babar 13*) lead England 354 by 49 runs
With Pakistan looking to set up a tricky fourth-innings chase on a National Stadium pitch showing some signs of deterioration, their top three all fell to Leach in a chaotic 10-minute spell immediately after they had taken the lead.
Saud Shakeel and Babar Azam added an unbroken 45 for the fourth wicket, battling through to the lunch interval, but England were on top at the break and had the better of a session that saw Pakistan add 78 runs for the loss of three wickets.
Masood had started with positive intent after batting through to stumps on the second evening and hit the first two balls of the third day for four, slashing Joe Root through the gully and driving him through cover. He skipped down to his fifth ball, chipping him down the ground for four more, and lofted a straight six to prompt an early change, with Leach replacing Root after only two overs.
Abdullah Shafique struck a couple of boundaries, taking on Mark Wood's short ball and pulling Pakistan into the lead by finding the gap between fine leg and deep backward square leg, but Leach struck in his second over of the day. Masood, still playing positively, got low to reverse-sweep, but Leach found some turn from a fullish length outside his off stump and Masood could only bottom-edge onto the base of leg.
Azhar Ali was greeted with handshakes by England's fielders but his final innings before his retirement from international cricket was all too brief. His fourth ball was full, pitching on leg stump, but turned sharply away from the bat as he looked to whip wristily through midwicket. It crashed into the top of off, and Azhar trudged off through a guard of honour from his team-mates.
Azhar had earlier been presented with a commemorative plaque and a shirt signed by his team-mates before play, and had his family watching in the stands. He finishes his Test career with 7142 runs at 42.26 and 19 hundreds.
At the start of his next over, Leach struck again. He trapped Shafique lbw, sliding one onto his front pad from around the wicket; Shafique didn't review, but ball-tracking technology subsequently predicted that the ball would have hit leg stump halfway up. Shakeel survived the hat-trick ball, but Pakistan were effectively 4 for 3.
Shakeel and Babar opted to dig in before the lunch break, both scoring at a strike rate below 45. They were cautious against Leach, who got the occasional ball to turn, and Robinson, who found some reverse-swing during a five-over burst and struck Shakeel on the helmet with a sharp bouncer.
Babar survived a tight lbw shout on review, having shimmied down and pushed Leach into the off side after the ball had flicked his front pad. England queried Joel Wilson's on-field decision, but Babar was saved by the fact the impact occurred more than three metres from his stumps.
Rehan Ahmed, England's legspinner, did not bowl a ball in the morning session but is expected to play a role in the afternoon.
Matt Roller is an assistant editor at ESPNcricinfo. @mroller98