A good start from openers Graeme Smith and Neil McKenzie helped South Africa cement their fightback against India by the end of the fourth day of the first Test in Chennai on Saturday.
India were bowled out for 627 in their first innings before South Africa replied with a solid 131 for one in their second innings to take a 44-run lead.
Neil McKenzie scored his second successive half-century and was unbeaten on 59 with Hashim Amla, on 35, at stumps on the penultimate day.
A fiery spell by South Africa paceman Dale Steyn brought the Indian innings to an abrupt end, the hosts taking a first-innings lead of 87 runs, at tea.
Steyn picked four wickets in the space of 14 runs as India added only 159 runs to their overnight 468, for the loss of nine wickets.
Makhaya Ntini (3 for 128) had done the damage earlier, claiming the wickets of Virender Sehwag, Rahul Dravid and Sachin Tendulkar, while spinner Paul Harris contributed with 3 for 204.
Earlier, Virender Sehwag posted a career-best of 319 and Dravid notched 10,000 Test runs while completing his 25th Test ton (111).
Morning session: (79 runs, 25 overs, 3 wickets)
Resuming on 309, Sehwag went past his career-best score with a single to fine leg off the first ball of the day. It was exactly fours years ago, March 28, 2004, that Sehwag had hammered the Pakistan bowlers enroute to a magical 309 at Multan.
With Sehwag looking good to break Brian Lara's world record of 400, it was not surprising to see the crowds flock to the stadium in numbers. A huge crowd had gathered outside the stadium wanting to get into the stands and watch Sehwag repeat his strokeplay of the third day.
Sehwag hit his first boundary in the sixth over of the day when he pulled Ntini to move to 319. He, however, fell to the very next delivery when he tried to play through the off-side but edged it straight to Neil McKenzie at first slip.
The 29-year-old was dismissed for an outstanding innings of 319 that stretched 531 minutes and included 42 boundaries and five sixes off 304 deliveries. He walked back to a standing ovation from the Chennai crowd, which was obviously a bit disappointed seeing him get out so early on day four.
Sehwag smashed 42 boundaries and five sixes in his 304-ball knock. The Indian opener is the only player along with the legendary Don Bradman and Brian Lara to score two triple centuries in Test cricket.
His 531-minute stay at the wicket saw him being involved in a world record two double century partnerships, a first in a Test innings. He added 268 for the second wicket with Rahul Dravid to follow up on his 213-run opening stand with Wasim Jaffer.
Sachin Tendulkar walked in to a huge reception, but failed to make it count. On a pitch, where every batsmen had scored runs at will, Tendulkar fell for a duck. He tried to drive Ntini through the off-side and was taken by Jacques Kallis at second slip as India slipped to 481 for three.
Sourav Ganguly hit a delightful boundary through the off-side to bring up India's 500 in 117 overs, the first time India had scored 500 against South Africa.
Dravid completed 10,000 runs in Test cricket with a single to the mid-wicket when his score was 80, becoming the third Indian and the sixth overall to do so. Playing in his 120th Test, he scaled the 10,000-run mark at an amazing average of 55.55 and celebrated the landmark by raising his bat.
He, Tendulkar and Lara are the only three players to complete 10,000 runs in both Tests and ODIs.
Ganguly played a few beautiful shots before he was caught behind off Harris for 24 as India slipped to 526 for four.
V V S Laxman took India past South Africa's first innings total of 540 with a neat-flicked boundary to the mid-wicket region on the 130th over.
Dravid was left one short of his 25th Test century when he finished 99 not out at the lunch break. India were a commanding 547 for four in 131 overs at lunch, having taken a seven-run lead.
The session was a hard-fought one as the South African bowlers bagged a few quick wickets. Sehwag's dismissal for 319 left quite a few million Indians, who were hoping he would score 400, disappointed. And Chennai's favourite batsman Tendulkar also disappointed in what could be his last Test innings at the venue.
Post-lunch session: (80 runs, 24.1 overs, 6 wickets)
Dravid completed his hundred in the first over after the break with a cracking straight boundary off Ntini. The former India captain's 25th Test century took 272 deliveries and included 13 boundaries.
Incidentally, he also completed 10,000 runs for India in Test cricket. He had completed 10,000 in Tests when his score was 80 but that also included the 23 he made for the ICC World XI against Australia in the ICC Super Series in 2005.
In the next over from Harris VVS Laxman cracked two more boundaries through the off-side as India's intent became clear.
However, against the run of play India lost the key wicket of Dravid. The right-hander was dismissed for a gusty knock of 111 that included 15 boundaries in 291 deliveries before he became Ntini's third victim of the day.
Out walked Mahendra Singh Dhoni to another huge roar from the crowd. He will also be leading the Chennai Super Kings in the forthcoming Indian Premier League tournament and is one of the adored players here.
Dhoni did not take time to get going. He reverse-swept left-arm spinner Harris for a boundary through third man off the third ball he faced.
However, the South African bowlers were quick to react and made life difficult for Dhoni with sharp bouncers. And it was one of those bouncers from Steyn that brought about Dhoni's dismissal, for 16, as he tried to fend the ball away; it got the glove and flew to wicketkeeper Mark Boucher.
India brought up 600 in the 146th over when Anil Kumble took a single on the leg side.
Steyn then showed his prowess when he claimed two wickets; his lethal inswing knocked out the middle stump of Kumble (3) and Harbhajan Singh (0), reducing India to 610 for 8.
R P Singh also had no answer to Steyn's reverse swing as the ball crashed on to his middle stumpl he was bowled for 0. India slumped to 612 for 9 in the 151st over, their last four wickets falling for four runs in the space of 21 deliveries.
Laxman made no attempt to protect last batsman S Sreesanth and took a single at every possible opportunity. Not surprisingly, Steyn bowled a quick bouncer that struck Sreesanth and left a painful swelling on his left arm, but he continued batting.
Laxman's tactics were strange, considering that he never attempted to take on the bowlers and was merely content to play for singles. He was the last man out when he got a leading edge that went straight back to the bowler, Harris.
Laxman was dismissed for 39 and India were bowled out for 627 in 155.1 overs, giving them a first innings lead of 87 runs at tea on the fourth day.
India lost their last six wickets for 54 runs in the space of nearly 20 overs, courtesy some lethal fast swing bowling by Steyn.
He finished with impressive figures of four for 103 in 32 overs, helping the visitors clean up the Indian tail pretty quickly.
Ntini, who bowled a great spell in the morning session, finished with three for 128 in 28 overs, while left-arm spinner Harris toiled hard for his three for 203 in 53.1 overs. It was a great effort by the bowlers as they restricted India to just 80 runs after lunch while claiming six wickets on a pitch that did not offer much help.
Post-tea session: (131 runs, 33 overs, 1 wicket)
South Africa got off to a good start. Graeme Smith led the charge with a boundary off the third ball of the innings off Sreesanth.
The second over from R P Singh was no better, as Smith carted him for three boundaries to race to 23 from just 12 deliveries, inclusive of five boundaries.
With the pacers looking totally ineffective, Harbhajan was introduced in the ninth over; he replaced Sreesanth, while Sourav Ganguly replaced R P Singh at the other end.
Harbhajan took no time in getting his first wicket; he trapped Smith leg before wicket for a quick 35 from 30 deliveries. The left-hander played a forward defensive shot but was struck on the pad and was ruled out by umpire Asad Rauf.
Kumble brought himself into the attack in the 14th over but was guilty of erring in length in his first over. Hashim Amla carried on from his hundred in the first innings as he cut the veteran leggie through point for a boundary.
In the next over, McKenzie lofted Harbhajan over mid-on for a boundary, perhaps signaling that they would not let the Indian spinners settle down. He repeated the dose on Harbhajan again in his next over, the 17th of the innings, when he lofted him again over mid-on to progress to 29.
Even Kumble found it difficult to stop the flow of runs as he conceded two more boundaries in his third over. South Africa were scoring at more than four-and-half runs per over and were 92 for 1 after 20, having overcome India's first innings lead of 87.
McKenzie played solidly and continued his good form from the first innings. He cruised to his half-century -- in the 29th over with two runs off part-timer Sehwag -- off 83 deliveries, having hit six boundaries.
While McKenzie took the initiative, Amla was quite content to hold the other end up and play for stumps.
The batsmen added 78 runs to take South Africa to 131 for 1 in 33 overs at close on day four for a lead of 44..
McKenzie was unbeaten on a fine knock of 59 from 98 deliveries, inclusive of seven boundaries, while Amla was not out on 35 from 70 deliveries, inclusive of four fours.
India's bowling was again a major let-down.
R P Singh continued to be way below par, giving away 27 runs in four overs, while Sreesanth went for 28 in six overs. Harbhajan took a wicket for 40 for 1 in 10 overs, while Anil Kumble finished with 27 runs from 10 overs.
The bowlers will have to brace for another hard day's work on Sunday, and with the batsmen not facing any real problems, South Africa will be confident of playing for a draw.