At lunch England, sent into bat by Sri Lanka captain Angelo Mathews on an initially overcast morning, were 57 for three having been 49 without loss.
Shanaka, the fifth bowler used by Mathews, did the damage with a spell of three wickets for one run in eight balls.
He removed England captain Alastair Cook for 16 and then dismissed both Nick Compton and Joe Root for ducks.
All-rounder Shanaka walked off with lunch figures of three wickets for six runs in five overs.
Also Read
England were making steady progress when 24-year-old medium-pacer Shanaka struck with just his seventh ball in Test cricket.
Cook, who started his innings needing just 36 more runs to become the first Englishman to score 10,000 in Tests, had rarely looked in trouble in more than an hour-and-a-half at the crease after getting off the mark with a four.
But his 52-ball innings ended when he was caught behind going for a cover drive off a wide but full delivery from Shanaka in the 21st over.
Root, England's recently crowned player of the year in all formats, was powerless to prevent further collapse on his Yorkshire home ground.
He went hard at a full ball from Shanaka and edged to Kaushal Silva in the gully.
Players from both sides wore back armbands in memory of all those killed by recent flooding and landslides in Sri Lanka.