Sri Lanka was on course for a series-closing victory over England after reaching 94-1 in its chase of 219 to win the third test at The Oval on Sunday.
After skittling England for 156, Sri Lanka seized control late on Day 3 as Pathum Nissanka played beautifully for 53 not out and was enjoying a 55-run partnership with Kusal Mendis (30 not out).
The tourists needed 125 more runs to win, though have already lost the series after defeats at Old Trafford and Lord's. England is seeking a second straight series sweep this summer, having beaten the West Indies 3-0 in July, but is now the big underdog.
It was a dominant day in south London for Sri Lanka, which started the day on 211-5, was dismissed for 263 to be only 62 runs behind after the first innings, and then bowled out a sloppy England batting unit in 34 overs.
Only a brilliant, counterattacking 67 from wicketkeeper Jamie Smith saved England from an embarrassing score in its second innings. The hosts were 82-7 at one point and failing to deal with some fine swing and seam bowling by Sri Lanka, but Smith came to the middle and flailed shots to all parts of the ground in a 50-ball knock that contained 10 fours and a six.
Aside from Smith and Dan Lawrence — whose cavalier 35 was exciting but hardly controlled — no other batter got above 12. Ollie Pope, a first-innings century-maker, was out for 7, opener Ben Duckett was dismissed also for 7 when mishitting a slog over fast bowler Asitha Fernando's head and star batter Joe Root only added 12 to his 13 from the first innings before being trapped lbw by Vishwa Fernando.
Lawrence's dismissal summed up England's often-strange approach as he advanced down the wicket and attempted a white ball-style heave, only to edge behind.
Lahiru Kumara was the pick of the bowling attack with 4-21 and the Sri Lankans were suddenly in with a big chance after being set 219 to win.
Nissanka brought up his second fifty of the match, this time off just 42 balls, and now has seven half-centuries in 11 tests.
Dimuth Karunaratne (8) was the only Sri Lankan batter to depart when he got a thick inside edge off Chris Woakes, who dived to take the return catch.
The pitch was offering some joy for England, with 20-year-old left-armer Josh Hull — who removed Sri Lanka captain Dhananjaya de Silva (69) and Vishwa Fernando (0) early on Day 3 to finish with figures of 3-53 in his first test match — getting plenty of movement.
Bad light brought an early end to play, by which time Mendis had joined Nissanka in taking the attack to England's bowlers.