That left the Proteas facing a tricky nine-over session before the close of Friday's second day.

All-rounder Stokes, 98 not out at tea on Friday's second day, went to three figures in unusual fashion when a straight drive off Kagiso Rabada deflected off the fast bowler's shin to take him to a 158-ball hundred, including six fours and three sixes.

But the left-handed batsman, dropped on 92, fell soon afterwards when a leading edge off Rabada flew high to mid-off where he was superbly caught by back-pedalling opposing captain Dean Elgar.

England, however, were still well-placed at 320-6, a lead of 169 runs, following a stand of 173 between Stokes and Foakes, who was 68 not out at the time of his skipper's dismissal.

The pair had come together with England on 147-5.

Their partnership was just what England, 1-0 down in this three-match series, required after an innings and 12-run defeat in the first Test at Lord's -- their first defeat after a run of four successive wins under the leadership duo of Stokes and coach Brendon McCullum.

And for all the talk of a new 'Bazball' aggressive style, the 31-year-old Stokes's well-paced innings on Friday -- his 12th hundred in 85 Tests and fourth against South Africa -- was also a triumph of largely orthodox batting.

Foakes then added to the Proteas' woes by going to his second hundred in 16 Tests -- and first at home -- when the 29-year-old Surrey gloveman late cut fast bowler Anrich Nortje for a ninth four in 206 balls faced.

Tailenders Stuart Broad, Ollie Robinson and Jack Leach all chipped in before Stokes called a halt to the innings.