"It is difficult to play spin on this pitch in the morning session and if we could take three wickets the match will end by mid afternoon," Mendis said.
Offspinner Randiv had Virender Sehwag caught at slip by Mahela Jayawardene without scoring and bowled Rahul Dravid for seven runs.
Murali Vijay was caught at short-leg by Mahela Jayawardene for 27 runs to give Randiv his third wicket.
Sachin Tendulkar reached 11 at the close with nightwatchman Ishant Sharma on two.
Samaraweera and Mendis came to Sri Lanka's rescue with their Sri Lanka record stand after Indian spinners skittled their lineup in the morning
session, taking six wickets for 98 runs.
The hosts resumed day four on 45-2 but left-arm spinner Pragyan Ojha sparked a collapse when he trapped nightwatchman Randiv lbw for six before claiming the prize wickets of Mahela Jayawardene for five and Kumar Sangakkara for 28 at the expense of one run.
Legspinner Amit Mishra had Anjelo Mathews caught by Tendulkar on five runs and dismissed Prasanna Jayawardene for nought lbw off successive deliveries to leave Sri Lanka at 87-7.
Samaraweera and Lasith Malinga resisted briefly with a 38-run stand for the eighth wicket before Sehwag trapped Malinga lbw for 15 runs to leave the hosts on a precarious 125-8.
Anchoring the innings
Samaraweera anchored the innings with a classic 83 off 139 balls including six boundaries before edging seamer Abhimanyu Mithun to wicketkeeper Mahendra Singh Dhoni.
Mendis brought up his maiden test and first class half-century and was last out for 78 caught by Suresh Raina off Mishra. He faced 157 balls,
hitting 10 boundaries and a six.
Mendis said he was uncertain of his form when he went in to bat and only wanted to support Samaraweera to score as many runs as possible.
"But I gradually grew in confidence to score runs myself," he said.
Mendis added that he had not paid much attention to his batting, concentrating on bowling only.
"Later I realised the importance of batting and worked very hard on it. I think I was rewarded for that."
Mishra was the pick of India's bowlers, going 3-47 while Sehwag had 3-51 and Ojha returned 3-89.
India was dismissed for 436 runs in its first innings in reply to Sri Lanka's 425.