Dean Elgar and Quinton de Kock struck centuries to help South Africa avoid the threat of a follow-on and reach 385-8 at stumps on Day 3 of the first test against India on Friday.
Spinner Ravichandran Ashwin took his 27th five-wicket haul in tests to keep India in control of the series opener, however, with South Africa still trailing by 117 runs.
After the Proteas resumed in some trouble on 39-3, Elgar scored 160 off 287 balls for the opener's 12th test hundred before De Kock attacked India's spinner to make 111 off 163 deliveries.
They put on 164 runs for the sixth wicket, allowing South Africa to ease past the follow-on mark.
At stumps, Senuran Muthusamy (12 not out) and Keshav Maharaj (3 not out) were in the middle.
Responding to India's first innings of 502-7 declared, South Africa - which, at one stage, was reeling on 34-3 - dominated the third day of the test and lost only two wickets in the first two sessions.
Ishant Sharma trapped Temba Bavuma (18) lbw before lunch, while Faf du Plessis fell for 55 in the afternoon to end a partnership of 115 runs with Elgar that resurrected the Proteas' innings.
That brought Elgar and De Kock together, the latter taking charge of the innings with a counterattacking knock to reach his fifth test century off 149 deliveries.
The breakthrough finally came in the 100th over when Elgar holed out to deep mid-wicket off Ravindra Jadeja (2-116).
De Kock helped South Africa cross 350 in the next over but fell to Ashwin, pushing the ball onto the stumps off his pads.
Ashwin made it a quick double blow as he bowled Vernon Philander for a 10-ball duck, and had figures of 5-128 from 41 overs.
India's big first-innings score was established on an opening stand of 317 runs between Mayank Agarwal (215) and Rohit Sharma (176).