The hosts, who trailed India by 192 runs in the first innings, fought back from 95-5 to reach 263-6 in their second knock by tea on the third day.
Chandimal and Thirimanne, who joined hands before lunch with their team still 98 runs away from making India bat again, launched a brilliant counter-attack to put on 125 for the sixth wicket.
Chandimal was unbeaten on a run-a-ball 98 with 11 boundaries and two sixes, and Thirimanne made 44. Sri Lanka now lead by 71 runs with four wickets in hand.
As the pair settled down, the Indians were left to rue the refusal by their powerful cricket board to use the Decision Review System for their bilateral matches.
Both batsmen were fortunate to get into double figures after surviving three appeals for catches close to the wicket -- two against Chandimal and one against Thirimanne – in the last three overs before lunch.
Replays showed all three catches were clean, frustrating India's bid to force an innings victory in the first match of the three-Test series.
Jehan Mubarak kept Chandimal company at tea on 23 after Thirimanne was snapped up at slip off Ravichandran Ashwin to give India its lone success in the post-lunch session.
Earlier, Kumar Sangakkara scored 40 in his penultimate Test and captain Angelo Mathews made 39, the pair adding 87 for the fourth wicket after Sri Lanka were reduced to 5-3.
Sri Lanka, who resumed at 5-2, lost nightwatchman Dhammika Prasad off the first ball of the day to give India a flying start.
Prasad attempted to fend off a short ball from Varun Aaron and gloved a catch to a diving Ajinkya Rahane at gully.
Mathews and Sangakkara took charge with a series of attacking shots, including a straight six and a reverse-sweep boundary by the Sri Lanka captain off Ashwin.
Sangakkara, who looked in good form during his 70-ball innings in which he hit five boundaries, was dismissed against the run of play 20 minutes before lunch.
The left-hander edged Ashwin to the slip region where Rahane dived to his left to pick up a stunning one-handed catch.
Sangakkara received a standing ovation from some 1,500 home fans as he walked back after playing his final innings at the Galle International Stadium.
Mathews fell in the next over to leg-spinner Amit Mishra, gloving a catch to Lokesh Rahul at silly-point. – AFP
Original source: SL avoids follow-on