Ben Stokes launched an astonishing assault which enabled England to give themselves plenty of time to push for victory, but the tourists had to work hard to take two South African wickets before the close on the fourth day of the second Test at Newlands on Monday.
Set to make a world record 438 to win, South Africa were 126 for two at the close. They used up 56 overs on Monday but will need to bat out another 90 on Tuesday to prevent England from levelling the four-match series.
Opening batsman Pieter Malan, making his Test debut, scored 63 not out and shared half-century partnerships with Dean Elgar (34) and Zubayr Hamza, who was caught behind off James Anderson in the penultimate over of the day for 18.
Stokes slammed 72 off 47 balls to overshadow a maiden Test century by Dominic Sibley, who continued his sedate progress as he took his overnight score of 85 to 133 not out. He reached his hundred off 269 balls and faced 311 deliveries in his innings.
England's batting on Monday was in dramatic contrast to their effort on Sunday when they ground their way to 218 for four off 79 overs. Sparked by Stokes they added another 157 runs off only 32 overs before declaring five overs after lunch on 391 for eight.
While Sibley continued to play the anchor role, Stokes went on the attack against every bowler he faced. He survived a chance on 38 when an attempted pull against Kagiso Rabada could not be held by a diving Quinton de Kock after the wicketkeeper ran about 35 metres in trying to take the catch.
Stokes was caught at long-on off left-arm spinner Keshav Maharaj after an innings which included three sixes and seven fours and had a large English contingent in the crowd roaring their approval.
Ollie Pope fell quickly but Jos Buttler continued the attack, hitting 23 off 18 balls as the lead went beyond 400.
South African captain Faf du Plessis chose not to take the second new ball when it was due after a maiden over by Dwaine Pretorius at the start of play. He perhaps reasoned that Maharaj had a chance of dismissing Stokes early in his innings.
The tactic backfired, however, as 28 runs were added in five overs before the new ball was taken, including sixes by Stokes off Pretorius and Maharaj.
Malan, out for five in the first innings, survived a review for leg before wicket against Stuart Broad when he was on four but then batted with patience to notch a patient maiden Test fifty off 144 balls which included only two fours.
England's first success was a first Test wicket for Joe Denly, who troubled the left-handed Elgar with his leg-spinners into the rough outside the left-hander's off stump, eventually having him caught behind off an edge so faint that Elgar unsuccessfully sought a review.