The wily spinner, playing his final Test, took five for 63 in the first innings and then claimed the wicket of Yuvraj Singh [ Images ] (5) in the second innings with the final delivery of the day to put the Lankans high in the saddle. He now needs just two wickets to breach the magical 800-wicket mark in Test cricket.
Lasith Malinga [ Images ] also proved his worth, claiming three for 33 in nine overs.
Following-on, India were left reeling at 181 for five in 59.3 overs at stumps, with VVS Laxman [ Images ] unbeaten on nine.
Despite rain washing out the second day and a session on the first, Sri Lanka are pressing for victory. India still need another 63 runs to avoid the humiliation of an innings defeat.
Sachin Tendulkar [ Images ] ignited India's hopes in the second innings with a fluent innings of 85 from 142 balls, inclusive of 11 boundaries and a six, before he was unfortunately adjudged leg before wicket to Malinga to a full delivery that was sliding down the leg side.
Tendulkar and Dravid (44) battled hard as they put on 119 runs in 254 deliveries for the third wicket. This was the 18th time the two batsmen had put on a 100-run partnership to improve their already existing world record.
Dravid also added another record to his name when he became the second batsman after Ricky Ponting [ Images ] to score 9000 runs in the number three position.
Gautam Gambhir [ Images ] was the first wicket to fall in India's second innings, caught behind off Lasith Malinga for a three-ball duck in the first over.
Virender Sehwag [ Images ], who scored a century earlier in the day, started off positively, hitting 31 from 30 balls, before he was brilliantly caught by Mahela Jayawardene [ Images ] at backward point off Chanaka Welegedara [ Images ].
Earlier, India were dismissed for 276 in their first innings, conceding a huge first innings lead of 244 runs, Sri Lanka having amassed 520 for eight declared in their first essay.
India lost their last five wickets for 24 runs in the space of ten overs, with Muralitharan claiming four of those to register his 67th five-wicket haul in Test cricket.
Sehwag slammed his 20th Test century before lashing at wide short delivery from Chanaka Welegedara and was caught at first slip after a splendid innings of 109.
Morning session: (28.2 overs, 120 runs, 5 wickets)
Welegedara and Angelo Mathews [ Images ] opened the bowling for Sri Lanka on Day 4, instead of Lasith Malinga, who had claimed an early wicket with the new ball on the third day.
Sehwag wasted no time in getting going and slammed Welegedara for two boundaries through the cover region to race to 95.
Another couple of boundaries in the next over from Mathews saw the dashing opener bring up his 20th Test century. The first was uppercut over the slips region while the second four was streaky, the inside edge just missing the stumps before racing to the boundary via the fine leg region.
Sehwag took just 108 balls to reach the landmark, hitting 18 boundaries and a six. It was his second successive century at the venue after his match-winning 201 two years ago.
He seemed in absolute control till he threw his wicket away after a splendid innings of 109. The right-hander lashed at a wide delivery from Welegadara and saw the ball fly to the first slip fielder.
Laxman joined him soon after in the dressing room as Sri Lanka's plans worked to perfection. The Hyderabad batsman pulled a short delivery from Malinga straight to the fielder on the square leg boundary and was out for 22.
Yuvraj Singh was positive from the outset and quick to despatch any loose deliveries on offer for boundaries. Interestingly, Sri Lanka kept Muttiah Muralitharan waiting and brought in part-timer Tillakaratne Dilshan [ Images ] ahead of the legendary spinner.
Yuvraj hit Dilshan for two successive boundaries in his first over as the bowler drifted wide and then gifted a full toss. The India left-hander was keen not to let the spinners settle down and went after Herath, hitting him through the covers and lofting him straight off the next delivery for back-to-back boundaries to race to 30.
Muralitharan was introduced quite late, in the 17th over of the day, and even he was carted for a couple of boundaries in his first over. Dhoni [ Images ] needed no second invitation as he pulled two short deliveries for fours through the leg side, in the 47th over.
Yuvraj registered the first six when he came down the wicket and lofted Herath over the ground to take the total to 238 for five after 50 overs.
It was Muralitharan who broke the partnership though when he bowled Dhoni through the gate. Dhoni, who scored 33 from 47 balls, was completely foxed by one that turned in sharply and crashed into his stumps.
In the next over, Yuvraj brought up his fifty off 58 balls when he swept Herath fine on the leg side for a boundary.
But spin wizard Muralitharan dashed India's hopes of saving the follow-on when he got the key wicket of Yuvraj. The left-hander edged behind an outgoing delivery and was caught at first slip after a brisk 52 from 64 balls, laced with eight boundaries and a six.
Harbhajan Singh [ Images ] compounded India's woes when he jumped down the wicket to Herath. He missed the ball and was stumped for two.
At lunch on day four, India were staring at the inevitable, reduced to 260 for eight in 58 overs in reply to Sri Lanka's mammoth 520 for eight declared.
The game turned on its head in the last 10 minutes of the session as India lost three wickets for seven runs in the space of 21 deliveries.
It was not long after the break that Muralitharan had his fourth wicket of the innings. Pragyan Ojha [ Images ] was beaten by one that bounced and spun sharply and edged it to first slip. He was dismissed for three.
Debutant Abhimanyu Mithun [ Images ] got off the mark in Test cricket in some style when he cut a short delivery from Muralitharan through point. In the next over, he pulled a short delivery from Herath through midwicket for his second boundary but didn't last long.
Deservedly, Muralitharan ended things when he bowled Mithun for eight. It earned him his 67th five-wicket haul in Test cricket.
The veteran spinner ended with remarkable figures of five for 63 in 17 overs as India were dismissed for 276 in 65 overs; they lost their last five wickets for 24 runs in the space of 10 overs.
Malinga also made an important contribution, taking two for 55 in 13 overs, troubling the Indian batsmen with his pace and length.
(India 2nd innings)
It was a rewind of the first innings for India, as Gautam Gambhir again perished in the first over. The left-hander was done in by Malinga for the second time in the match, this time caught behind for a three-ball duck.
Fresh from a century earlier in the day, Sehwag again went after the Sri Lankan bowlers. Welegedara was hit for two boundaries in his first over and the India opener repeated the dose in the next over from Malinga to take India to 18 for 1 after three overs.
Interestingly, in the third over, Sehwag was caught and bowled off a no-ball from Malinga, who started celebrating, failing to hear the umpire's call.
There was no stopping Sehwag though as he hit Welegedara yet again for two more boundaries through the off-side. Sri Lanka tried to stop the flow of runs from Sehwag's end as they spread the field when he came on strike but attacked Rahul Dravid [ Images ] from the other end.
The boundaries dried up and Sehwag decided to break the shackles. He went after a wide, rising delivery from Welegedara, only to get an edge to Mahela Jayawardene at backward point. He was dismissed after quick 31 form 30 balls, which was laced with six boundaries.
That left India's two most experienced batsmen -- Dravid and Sachin Tendulkar -- with the difficult task of guiding India to safety.
Muralitharan came on to bowl in the 17th over of the innings and was up against Tendulkar. A perfect contest between the world's highest wicket-taker and run-getter was set up.
Despite falling to Muralitharan in the first innings, Tendulkar adopted a positive approach and hit the bowler for two boundaries in his second over.
At tea on day four, India were 68 for two in 21 overs. Dravid was on 12 (58 balls) and Tendulkar on 21 from 38 balls, having hit four boundaries.
While Dravid was yet to open his boundary count after nearly two hours at the crease, Tendulkar was positive, looking for runs at every opportunity.
He guided a slower delivery from Mathews in the wide gap between slips and then in the next over drove Muralitharan through covers for a couple of boundaries.
Meanwhile, Dravid, became the second batsman in Tests to score 9000 runs in the number three position behind Australia [ Images ] captain Ricky Ponting.
The former India captain got his first boundary off the 79th ball he faced when he hit a short delivery from Dilshan through the off-side, in the 29th over.
Tendulkar completed his half-century off 82 balls with a single on the leg side off Dilshan in the 37th over.
While Dravid (35 from 116 balls) was content to play out time, Tendulkar at the other end was looking to keep the scoreboard moving as he made 60 from 107 balls, with the help of nine fours.
Dravid also notched another record for the most deliveries faced. The right-hander, who is playing his 140th Test, went past Allan Border's [ Images ] record of 27002 balls faced in 156 Tests.
Tendulkar was growing in confidence and he proved that by stepping down the wicket to Muralitharan and depositing him over long-on for a six, in the 46th over.
The duo, who hold the record for the most century partnership in Test cricket, improved it further as they brought up their 18th hundred partnership courtesy of that six.
With the spinners not able to make an impression, Sri Lanka brought in pacer Malinga to make the breakthrough.
And the speedster struck in the first over of his new spell when he had Dravid caught at leg slip after a long vigil of 212 minutes, scoring 44 runs in 152 balls.
Dravid and Tendulkar partnership helped India make steady progress as they put on 119 runs in 254 deliveries for the third wicket.
Malinga then dealt India another huge blow when he claimed the wicket of Tendulkar, who hit a fluent 85.
Tendulkar, who hit 11 boundaries and a six in his 142-ball knock, was unlucky to be ruled out leg before wicket as he missed a full delivery that was sliding down the leg side.
Fittingly, Muralitharan ended the day with a wicket, his 798th in Tests, when he got Yuvraj Singh caught at slip for five.
At stumps, India were looking at the inevitable as they finished the day on 181 for five in 59.3 overs. The only interest on the final day is how long India can survive and whether Muralitharan can get to 800 wickets.
Sure, Muralitharan was the day's hero, with five wickets in the first innings and one in the second.
Malinga too was impressive in the second innings as he used the reverse swing to good effect.