Stokes slammed 258 and Bairstow made 150 not out before England declared on 629 for six. The pair shared a world Test record sixth wicket partnership of 399. Stokes' score was the highest by a number six batsman in Tests.
Stokes followed up by having South African opening batsman Dean Elgar caught at point as South Africa reached 141 for two at the close, still 488 runs behind.
He reached 250 with a six off Kagiso Rabada to become the fastest to the mark in Tests, beating Virender Sehwag's effort for India against Sri Lanka in Mumbai in 2009 by 11 balls.
With a declaration imminent, Stokes pounded the next delivery into the stands for another six before, in trying to hit a third, he skied the ball to AB de Villiers at mid-on. De Villiers dropped it but ran out Stokes with a direct hit to the bowler's end.
Also Read
======================
The South African bowlers had no answer to a relentless assault, which started with 45 runs scored off the first four overs of the day, bowled by Morne Morkel and Chris Morris.
The left-handed Stokes needed only 12 balls go from his overnight 74 to his third Test century, which he made off 105 deliveries with 16 fours and a six. He quickly went past his previous highest Test score, 120 against Australia at Perth two seasons ago.
South African captain Hashim Amla was soon forced to place fielders on the boundary on both sides of the wicket but Stokes continued to power the ball past them. By the end of the first hour, which yielded 103 runs off 13 overs, there were five men on the boundary.