At tea, England were 153 for for four in reply to Pakistan's first innings 339, a deficit of 186 runs.
Cook was 75 not out, having gone past India great Sunil Gavaskar's record of 9,607 runs to become Test cricket's highest-scoring opener.
Jonny Bairstow was unbeaten on one after leg-spinner Shah accounted for Joe Root (48), James Vince (16) and the recalled Gary Ballance (six).
Amir, making his return to Test cricket at Lord's -- the scene of his 2010 spot-fixing crime which saw him given a five-year ban from cricket and a jail term for deliberately bowling no balls as part of a betting scam, opened the attack.
More From This Section
Left-arm quick Amir, who served a five-year ban and was given a jail sentence for his part in the spot-fixing row, should first have had Cook out for 22.
Cook was drawn forward by an excellent delivery only for first slip Mohammad Hafeez to drop the routine catch.
It was a similar story when Cook, now on 55, again edged Amir but wicket-keeper Sarfraz Ahmed, going slightly to his left, floored the two-handed chance.
Amir screamed in frustration before sharing a wry smile with captain Misbah-ul-Haq, who gave the 24-year-old paceman a consoling pat on the back.
After the early loss of opener Alex Hales, Cook and new number three Root shared a stand of 110.
Cook, belying his reputation as a steady run-maker, struck three fours in four balls as Rahat Ali strayed onto the left-hander's pads.
Root joined in with five fours, including a classic straight drive off Rahat.
But Yasir turned the tide after lunch when he had Root carelessly hole out off a miscued sweep.
Earlier, England all-rounder Chris Woakes took a Test-best six for 70 as Pakistan, 282 for six overnight, were bowled out for 339.
Misbah only added four to his overnight 110 not out before he was bowled by Stuart Broad after the 42-year-old had become the oldest player in 82 years to make a Test century on Thursday.
Amir, booed by a small section of a capacity crowd as he walked out to bat, inside edged his first ball in Test cricket in six years, from Broad, for four.