At tea England were 155 for six needing a further 128 runs to reach their victory target of 283.
Jonny Bairstow (28 not out) and all-rounder Chris Woakes (five not out) — who had already taken 11 wickets in this match — were still at the crease but with just the tail to come.
The most England had ever made before to win in the fourth innings of a Lord’s Test was 282 for three against New Zealand in 2004.
If England achieve their target in this match, it would be the second-highest such chase in a Lord’s Test behind the West Indies’ 344 for one back in 1984.
England were making steady progress at 135 for four when leg-spinner Shah, who took six for 72 in the first innings, struck Sunday. A ball after Gary Ballance had pulled him for four, Shah bowled the recalled left-hander behind his legs for 43 with a delivery that spun out of the rough.
Moeen Ali (two) then charged down the pitch in an attempt to drive Shah, only to be bowled between bat and pad by a well-flighted delivery. Shah had taken two wickets for two runs in six balls and England were 139 for six.
Earlier, Pakistan’s Rahat Ali removed England’s top three batsmen in a breathless pre-lunch session that saw the hosts score 90 runs in 22 overs.
England captain Alastair Cook launched the chase with a four off the very first ball of the innings when he cut a loose Mohammad Amir delivery to the boundary.
All the pre-match focus had been on Amir, making his return to Test cricket at the scene of his 2010 spot-fixing crime. But it was fellow left-arm quick Rahat who stunned England.
His back-off-a-length ball had left-hander Cook (eight) edging through to wicket-keeper Sarfraz Ahmed. Cook’s opening partner Alex Hales made a brisk 16 before carelessly chasing a wide ball from Rahat outside off stump, with Mohammad Hafeez holding a good catch at first slip.
Joe Root, England’s new number three, struck two superb cover-driven fours off Rahat — one of the back foot and the other the front.
But the star batsman fell into a hooking trap on nine when he paddled a Rahat short ball to Shah, set back at deep square leg. James Vince too got off the mark with a cover-driven four off Rahat.