India were bowled out for 193 in their second innings midway through Tuesday, leaving Sri Lanka with an improbable winning target of 372 in four-plus sessions.
By stumps, the hosts had battled to 4-84, still trailing by 287 but with Sonal Dinusha and captain Dhananjaya de Silva having been able to thwart India's charge by safely reaching stumps following an excellent partnership.
First innings centurion Dinusha was 25 not out off 36 balls and de Silva was also still at the crease on 31 from 73 balls.
In the morning session, India had lost four wickets to reach 4-116 at lunch, scoring quickly while having an eye on possible bad weather as they attempted to force a win.
Rishabh Pant led the way for India on either side of lunch. He hit 50 off 53 balls including eight fours and two sixes before being out for 66 off 69.
First-innings centurion Devdutt Padikkal added 44 off 75 and KL Rahul 35 off 47 before India were all out for 193 in 48.5 overs.
Left-arm spinner Prabath Jayasuriya picked two wickets before lunch, including trapping Shubman Gill on eight, while pacer Asitha Fernando took 4-31.
Pant and Ravindra Jadeja (nine) combined for 54 off 60 balls until Pant was sent back in the 41st over by Lahiru Kumara. India lost their last four wickets for just 19 runs.
Sri Lanka's second innings was delayed due to a passing shower, but they didn't get a good start after play resumed.
Mohammed Siraj bounced out opener Nishan Madushka for six and Manav Suthar struck twice. Lahiru Udara was caught on 16 and Suthar trapped Pasindu Sooriyabandara for a golden duck.
Sri Lanka were sinking fast at 3-21 in the 11th over then 4-47 in the 22nd when Kamindu Mendis was caught on two at slip off Prasidh Krishna.
But de Silva and Dinusha dug deep to bat out the last hour and must do the same for six more hours on the final day on Wednesday if Sri Lanka are to avoid defeat.