Jacques Kallis' career-best 224 and 160 not out from AB de Villiers allowed South Africa to declare at 580-4 on day two of the series decider against Sri Lanka at Newlands.
Sri Lanka captain Tillakaratne Dilshan, who had opted to bowl first the previous day on a flat pitch, led his side's reply in thrilling fashion before holing out for 78 off 79 balls as the tourists closed at 149-2.
Kallis, on 159 overnight, completed the second double century of his career as he and De Villiers extended their third-wicket stand to 205 during the morning.
He fell on the stroke of lunch, caught by a tumbling Angelo Mathews at mid-on after failing to get hold of a lofted drive, giving left-arm spinner Rangana Herath (1-108) a long-awaited breakthrough.
Having faced 325 balls and hit 31 fours and a six, Kallis, playing in his 150th Test, was given a standing ovation as he returned to the pavilion.
De Villiers went into overdrive after the break, bringing up his 13th Test hundred from 176 deliveries before slamming another 60 runs off his next 29 balls.
Jacques Rudolph, slotting in down the order after his recent string of failures as an opener, provided support with an unbeaten 51 in a fifth-wicket alliance of 127 at more than six-an-over before the declaration came.
Dilshan and Lahiru Thirimanne navigated their way to 29-0 in the eight overs prior to tea but Sri Lanka lost Thirimanne, bowled for 23 by Morne Morkel (1-55), early in the evening session.
The visitors nevertheless maintained their attacking philosophy, Dilshan going to his half-century from 41 balls and hammering 12 boundaries in all before trying one big shot too many against leg-spinner Imran Tahir (1-15).
Proteas captain Graeme Smith took a well-judged catch after making good ground at long-on to get rid of his opposite number.
Mahela Jayawardene (7no) joined Kumar Sangakkara (35no) through to the close, which came with Sri Lanka trailing by 431.
Jayawardene survived a referral in the final over, Tahir convinced he had his man lbw, but replays vindicated umpire Richard Kettleborough's judgment.