England bounced back after being spun out cheaply by Sri Lanka to leave the first cricket Test evenly poised at the Galle International Stadium on Tuesday.
At the end of an eventful second day's play in which 17 wickets tumbled on a slow pitch, Sri Lanka led the tourists by 209 runs with five second innings wickets in hand.
Left-arm spinner Rangana Herath grabbed six wickets as England were bowled out for 193 in their first innings after skipper Mahela Jayawardene's 180 had lifted Sri Lanka to 318 earlier in the day.
But the hosts slumped to 84-5 in their second knock, four of those wickets falling to off-spinner Graeme Swann, to set up a thrilling finale.
Swann, who had failed to take a wicket in the first innings, ripped through the top order in the final session of play.
At stumps, Dinesh Chandimal was unbeaten on 17 and Suraj Randiv was on two.
England lasted just 46.4 overs as the world's number one Test side, still to recover from a 3-0 thrashing by Pakistan in the United Arab Emirates earlier this year, once again fumbled against spin.
Ian Bell top-scored with 52, but England lost their way before defiant batting by the tailenders pushed the total from a shaky 92-6.
Stuart Broad smashed 28 in a 30-run partnership for the seventh wicket with Bell, taking 18 runs in four balls from seamer Suranga Lakmal that included three boundaries and a six.
Swann's 24 runs came from six fours and England's tail prospered further when James Anderson (23 not out) and Monty Panesar (13) put on 36 runs for the last wicket.
England will slip to number two behind South Africa in the official rankings if they lose the two-Test series.
The tourists lost opener Alastair Cook in the second over of the innings before a run had been scored when he was trapped leg-before by Lakmal.
Jonathan Trott and captain Andrew Strauss put on 40 for the second wicket, before both fell in successive overs from Herath.
Trott was stumped for 12 and found himself knocked to the ground after colliding with celebrating wicket-keeper Prasanna Jayawardene.
Strauss departed in Herath's next over for 26, given out leg-before by the TV umpire after on-field official Asad Rauf turned down a loud appeal by the Sri Lankans.
Kevin Pietersen failed to add to his lunch score of three when he was bowled off the inside edge of the bat by an incoming delivery from seamer Chanaka Welegedara.
Earlier, Sri Lanka added 29 runs to their overnight score of 289-8 before being dismissed 30 minutes after the start of play.
Anderson finished with a five-wicket haul when he ended Mahela Jayawardene's 394-minute knock through a catch by wicket-keeper Prior.
The Sri Lankan captain hit 22 boundaries and three sixes in his 30th Test century which helped the hosts recover from a disastrous 15-3 on the opening day.