Debutant Stephen Cook and Hashim Amla shared a double century partnership for South Africa before England fought back on the first day of the fourth and final Test at SuperSport Park on Friday.
Cook made 115 and Amla hit 109 in a South Africa total of 329 for five at the close of play.
The pair put on 202 for the second wicket before Amla's dismissal sparked a collapse in which four wickets, including that of Cook, fell for 36 runs.
Temba Bavuma and Quinton de Kock restored South Africa's advantage with an unbeaten sixth wicket stand of 56. Cook, called up at the age of 33 when the South African selectors finally opted for a specialist opening batsman to partner Dean Elgar, was calm and organised from the start of his 218-ball innings during which he hit 14 boundaries.
Cook was on 97 when Amla was dismissed and was still two short of his century when AB de Villiers was caught at second slip off Stuart Broad for his second duck in three innings since being appointed captain. Cook went to his century off 187 balls when he tucked Stokes through midwicket for two and added 15 more runs before edging a ball from Chris Woakes into his stumps.
Brief Scores
SA: 329/5 (Bavuma 32*, de Kock 25*) vs England.