India ended their second innings on 80 for three as they launched an assault to try and negate a difficult wicket that was still helping the bowlers.
Rohit Sharma finished not out on 16 and Shreyas Iyer on 4, with Yashasvi Jaiswal (28), Shubman Gill (10), and Virat Kohli (12) being the wickets to fall.
There will be plenty of scrutiny of the Newlands pitch with the match completed in 642 balls, the shortest-ever test in which there has been a winner, beating Australia’s 656-ball victory over South Africa in 1932.
South Africa, who won the toss and elected to bat, will look back on a desperately poor first innings in which they were bowled out for 55 on a record-breaking opening day.
They gave themselves a fighting chance by dismissing India for 153 when the visitors lost six wickets for the addition of no runs, the first time that has happened in 147 years of tests.
But India seamer Jasprit Bumrah took 6-61 as the tourists bowled South Africa out in their second innings for 176 on the stroke of lunch on the second day to set up the win.
Bumrah bowled a superb probing line but also profited from poor shot selection from the home batters, who seemed in a hurry to score runs on the tricky wicket.
South Africa opener Aiden Markram scored a quick-fire 106 as he defied the conditions but lost partners at regular intervals, which forced him to try his hand.
Markram raced to his century in 99 balls but played one big shot too many as he skied a Mohammed Siraj delivery to Rohit Sharma at mid-off to end an innings of 17 fours and two sixes.
South Africa won the first test by an innings and 32 runs.