Pakistan were 214 for eight in their second innings at the close, a lead of 281 runs, after leg-spinner Shah took six for 72 in England's first innings 272.
But at stumps he was shaking hands with Chris Woakes after the Warwickshire all-rounder had taken five for 31 to follow the lively paceman's Test-best haul of six for 70 in Pakistan's first innings 339.
Woakes's 11-wicket haul was the first time he had grabbed at least 10 in a Test match.
Sarfraz Ahmed (45) and Shah, promoted from his first innings position of number 11, frustrated England in a seventh-wicket stand of 40.
Both batsmen were dropped off the luckless Steven Finn as the fast bowler went wicketless on his home ground.
Shah was on two when he chipped Finn out onto the offside and a diving Stuart Broad just failed to cling on to a tough low chance.
Fortunately for England, it was not too costly a miss with Woakes producing even simpler chances that Bairstow held to get rid of both the gritty Ahmed and Wahab Riaz (nought).
But Finn knew it wasn't his day when Shah, on one knee, hoisted him for four high over deep square leg.
Pakistan were 40 for one at lunch after Mohammad Hafeez had carelessly fallen for a duck in cutting Broad straight to Joe Root at second slip.
Azhar Ali (23) then fell lbw to a desperately tight umpire's call as Woakes reduced Pakistan to 59 for three.
Misbah, in his maiden Test knock at Lord's, had made 114 in Pakistan's first innings.
Pakistan had never previously lost a Test when Misbah had
made a hundred and never won one when he had made a duck but one of those records was now under threat.
The unsettled Younis Khan played on to Ali for 25 two balls after driving him for four.
Earlier, Shah produced the best innings bowling by a visiting spinner against England in a Test at Lord's since Sid Pegler's seven for 65 for South Africa back in 1912.
Variations in pace and flight saw Shah repeatedly pose problems on an unresponsive pitch.
Both sides knew that Shah was likely to be an even greater threat on a wearing fourth-day surface tomorrow.
England resumed on their overnight 253 for seven, after Shah induced a middle-order collapse yesterday.
