At lunch, England were 90 for three in their second innings, needing a further 193 runs to reach their victory target of 283.
James Vince was a Test-best 41 not out and the recalled Gary Ballance 15 not out after Rahat had taken three wickets for 36 runs in eight 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.
But it was fellow left-arm quick Rahat who stunned England.
Also Read
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.
Rahat had taken two for eight in 13 balls and England were 32 for two.
Joe Root, England's new number three, got off the mark with a back-foot cover drive for four off Rahat and also drove him through the same region, off the front foot, for another boundary.
Root was out for nine and England were 47 for three.
Vince too had gotten off the mark with a cover-driven four off Rahat.
Yet to play a major Test innings, Vince was almost out on nine when his edged drive off Rahat flew to Younis Khan at second slip.
Younis dropped the low one-handed chance and just failed to cling on to the rebound.
Vince struck three fours in as many balls off Wahab Riaz, the third of Pakistan's three left-arm quicks.
That saw Vince in his fourth match at this level, surpass his previous Test-best of 35 against Sri Lanka a Chester-le-Street in May.
Earlier, Pakistan added just one run to their overnight 214 for eight as Stuart Broad had both Shah, out for a Test-best 30 and Amir caught behind.
Pace-bowling all-rounder Chris Woakes led England off the field after taking five for 32 for a match haul of 11 for 112.
Only the West Indies, with 344 for one in 1984, had ever made more in the fourth innings to win a Test at Lord's.