The pair frustrated the Sri Lankan bowlers by not taking any chances and scoring runs only off the loose balls.
Kumar Sangakkara, the Sri Lanka captain, kept changing his bowlers, even asking spinner Suraj Randiv to take the second new ball, but the two batsmen were equally adept to the challenge.
Wicket-keeper Prasanna Jayawardene's dropped catch, when he put down a sitter from Tendulkar when he was on 29, proved to be an expensive miss for the home team.
Tendulkar made them pay heavily for the mistake, striking one six and 14 fours in reaching his ninth Test hundred against Sri Lanka off 167 balls with a sweep shot for four off Randiv.
Inspired by his senior partner, Raina eased to his maiden test fifty off 95 balls with eight fours.
Virender Sehwag said the pitch was still good and was hopeful the Indian batsmen will bat through the fourth day on Thursday.
"The wicket was so good to bat on and I knew somebody will make a big one," he said of Tendulkar's century.
India come out strongly in reply to Sri Lanka's massive total, with openers Sehwag and Murali Vijay sharing 165 runs.
But Sri Lanka's spinners Suraj Randiv and Ajantha Mendis struck back with three wickets for eight runs as the visitors went for lunch on 173-3.
Sehwag, one run short of a century, stepped out to hit off spinner Randiv and was beaten by the bounce to be stumped by wicketkeeper Prasanna Jayawardene. He hit 15 boundaries in his 101-ball innings and his dismissal was Randiv's maiden test wicket.
Vijay departed soon after Sehwag for 58, trapped lbw by Mendis. Randiv then trapped Rahul Dravid lbw for three runs.
Randiv said he was happy to have a batsman of Sehwag's calibre as his maiden test wicket.
"I expected him to do something different because he was stuck at 99. Then I bowled a 'doosra' and got the wicket," he said.
"We have to work hard and we have to stop runs. It's very difficult to get wickets and we have to be disciplined," he said about the task facing them on the fourth day.
Randiv has replaced Muttiah Muralitharan who retired with a record haul of 800 wickets after the previous test in Galle. He returned bowling figures of 2-108 while Mendis had 2-92.
Sri Lanka won he first Test of the three-match series.