Three key wickets from Tillakaratne Dilshan helped Sri Lanka peg back a Sachin Tendulkar-inspired India in an action-packed end to the fourth day's play.
India began the final session in cruise control thanks to Tendulkar's magnificent double hundred, but the little master's departure early on sparked a mini-collapse.
Dilshan - who got rid of Tendulkar - then snapped up the key wickets of skipper Mahendra Singh Dhoni and hard-hitting tail-ender Harbhajan Singh, while Ajantha Mendis picked up his fourth wicket of the game as the visitors - with 9/669 on board - could only limp to a 27-run lead at stumps.
With Sri Lanka's regular bowlers unable to inflict any substantial damage in the day's entirety, it was part-time spinner Dilshan who came to the fore for the hosts in only the third over of the final session.
First to depart was Tendulkar, caught on 203 by keeper Prasanna Jayawardene when attempting to block Dilshan's flighted delivery.
With the 95-run sixth-wicket stand broken, Sri Lanka were keen to make further inroads and, just two balls after Tendulkar's fall, new man Harbhajan's drive through midwicket only found the safe hands of skipper Kumar Sangakkara.
India virtually clammed up following the double blow, but Dhoni and Abhimanyu Mithun managed to prod the score past the Sri Lankan total - hitting the odd boundary along the way as well.
However, things worsened for India as Dhoni - who had worked hard and long for his 76 off 138 balls - became Dilshan's third wicket, caught by the bowler himself off a mistimed slog.
Mithun, who looked to have settled in for a last-gasp stand-off, was unceremoniously bowled by Ajantha Mendis just nine short of his maiden half-century.
Having begun the day on 4/382, Tendulkar and Raina were off to a positive start, taking 13 runs off only the third over of the day including a huge six over long-off by Raina.
And Raina capped an incredible debut in style, smashing Dammika Prasad for a boundary to bring up his maiden Test century, along with the 200-run partnership, to help India avoid the follow-on going into lunch.
Resuming after the interval at 4/477, Tendulkar and Raina looked set to continue their dominance of the bowling attack and add to India's total.
But the visitors were dealt a cruel blow early on as Raina was caught out by a quicker delivery from Ajantha Mendis and was caught by Sangakkara.
However, Tendulkar's innings - 202 off 343 deliveries - backed by Dhoni's quickfire 50 took the visitors to 5/589 going into tea.