England 339 for 9 (Root 186, Buttler 55, Embuldeniya 7-132) trail Sri Lanka 381 (Mathews 110, Dickwella 92, Perera 67, Chandimal 52, Anderson 6-40) by 42 runs
Galle: Joe Root hit a magnificent 186 but his dismissal from the final ball of the third day left Sri Lanka with a slight advantage in the second Test in Galle.
Root, who scored 228 in the first Test, was superbly run out by Oshada Fernando at short leg to leave England 339-9.
The England skipper had led the tourists' recovery from 132-4 to a position where they closed just 42 runs adrift of Sri Lanka.
Left-arm spinner Lasith Embuldeniya took a remarkable 7-132 for the hosts.
The 24-year-old, playing in only his ninth Test, dismissed Dom Bess and Mark Wood in the final half hour as Sri Lanka finished strongly on a day otherwise dominated by Root.
The right-hander put on 97 with Jos Buttler, who made 55, and shared a crucial stand of 81 for the seventh wicket with Bess.
Root's innings - one of the finest of his career - saw him become the first England Test player since David Gower in 1985 to follow a double hundred with a score in excess of 150.
It prevented England conceding a significant first-innings deficit but, with him dismissed, Sri Lanka could still take a useful lead into their second innings.
Root, who battled cramp and stiffness throughout the afternoon on Sunday, had to drag himself from the field after his dismissal. He was four balls short of batting throughout the day.
The 30-year-old clipped a ball from Dilruwan Perera off his pads but it was brilliantly parried by Fernando, who then threw down the stumps from close range with Root coming up short with a weary dive.
Thirty minutes earlier, Root was batting serenely and Bess going well for his 32. England looked set to reach the close within touching distance of Sri Lanka with four wickets still intact.
A first-innings lead looked possible but an entertaining Test swung again.
Embuldeniya had Bess caught at slip with a ball that turned and Wood played a rash slog-sweep to nick the ball to the same fielder.
Jack Leach and James Anderson now face the task of getting England as close to Sri Lanka's 381 as possible.
Any lead, on a pitch that is starting to turn for the spinners, could be crucial.
England lead the two-Test series 1-0.