When the bad light forced early stumps on the third day, Sri Lanka were 165 for four, trailing by seven runs, with skipper Dinesh Chandimal (13) and Niroshan Dickwella (14) at the crease.
Sri Lanka had taken a firm grip over the proceedings but paceman Umesh Yadav removed both Thirimanne and Mathews in the post-tea session to take off a bit of pressure from the hosts.
Thirimanne and Mathews added 99 runs for the third wicket to negate the twin blows from Bhuvneshwar Kumar, who removed both the Sri Lankan openers -- Sadeera Samarawickrama (23) and Dimuth Karunaratne (8).
While the chips are already down for the hosts, they further received a setback when paceman Mohammed Shami walked off the field due to a right hamstring issue towards the end of the day.
India resumed at a precarious 74 for five and managed to add 98 more runs to their overnight total, which was their second lowest score against Sri Lanka at home.
It is only the second time the Islanders have dismissed India in their own den below 200, after the hosts were dismissed for 167 in Chennai in December 2005.
On the other side, everything seem to fall in place for the tourists as they bowled India out to be in an advantageous position, resisted the Indian attack nicely and successfully called two DRS reviews.
Having taken a review to overturn umpire Joel Wilson's decision which resulted in Ravindra Jadeja's dismissal, Sri Lanka took another review successfully to save Karunaratne even though the opener did not last long.
The left-handed opener was given out trapped in front by Mohammed Shami but they reviewed the decision successfully.
However, Bhuvneshwar bounced back to send back Karunaratne and Samarawickrama in successive overs to brighten India's hopes.
It was not the case to be as vice captain Thrimanne and former captain Mathews, who is promoted to four in his comeback match, put on a composed approach in their left-right combination.
Barring the blip when Thirimanne was dropped by Shikhar Dhawan in the slip cordon, the Lankans did not take a step wrong as it turned out to be another frustrating day for the home team.
Interestingly, both Thirimanne and Mathews both faced 94 balls each in their innings and struck eight boundaries each.
Earlier, coming out to bat at an overnight score of 47, Cheteshwar Pujara (52 off 117) completed his half-century in the morning but could not make it big after being cleaned up by Lahiru Gamage (2/59) with a superb in-cutter.
Wriddhiman Saha (29) and Ravindra Jadeja (22) produced a brisk 48-run seventh wicket partnership but off-spinner Dilruwan Perera (2/19) struck twice in space of three ball to remove both.
Perera broke the partnership as the tourists successfully used a review to overturn the decision of Joel Wilson who stood in for indisposed Richard Kettleborough.
Jadeja was trapped in line but was given not out by the umpire as it seemed that the ball might have nicked the bat first but the review made it clear that there was pad first and the left-hander had to walk back to the pavillion.
Two balls later, Wriddhiman Saha got out with a faint edge which was taken by Mathews at the first slip as India reviewed unsuccessfully.
Bhuvneshwar Kumar (13) and Mohammed Shami (22) made some quick runs. Shami was later involved in a 26-run last wicket partnership with Umesh Yadav (6 not out) to prop up India's total.