India took a 17-run first-innings lead, and was 13-1 in its second innings at tea, with Murali Vijay on 11 and Cheteshwar Pujara on 2.AB de Villiers top-scored for South Africa with 63, while captain Hashim Amla (43) and left-handed opener Dean Elgar (37) added 76 runs in a defiant third-wicket partnership.
Ashwin, who has established himself as India's strike bowler, reached 150 wickets in 29 tests with his 13th five-wicket haul.
Spinners took all 10 South Africa wickets, with left-armer Ravindra Jadeja taking three and legspinner Amit Mishra two.
Ashwin grabbed three wickets in the morning session to wrest the initiative back, as he dismissed overnight batsmen Amla and Elgar.
Amla struck six fours before he jumped out and was stumped as the ball bounced off wicketkeeper Wriddhiman Saha's chest and hit the stumps.
Elgar tried to heave Ashwin against the turn but edged the ball high for Jadeja to take a simple catch at backward point.
De Villiers then propped up the innings with his 37th half-century in 99 matches.
De Villiers, who struck three centuries in the preceding five-game one-day international series which South Africa won 3-2, was scratchy through most of the innings.
He got past 50 with a slog-swept four off Jadeja, and was the ninth man out as he was bowled by Mishra.
De Villiers had a fortunate escape, having been caught close-in off Jadeja on 7, but was called back after replays showed it was a no ball.
India set for first innings lead after England fightback