The tourists needed four wickets at the start of play and threatened to race over the line in style as Stuart Broad, Mark Wood and Dom Bess left the Proteas on the brink at 138-9.
They were one ball away from a triumphant finish to their stay in Port Elizabeth but found themselves subject to an astonishing display of tailend hitting as Keshav Maharaj (71) and Dane Paterson (39no) swung their way to a 99-run partnership.
With the ball disappearing to all parts of the ground, it required a run out to finish the job, Sam Curran throwing down the stumps as Maharaj sprinted to bring up the century stand.
The result marks a notable achievement for Joe Root and his side, the first time England have enforced a follow-on overseas since 2013 and the first time they have done so in a winning cause since 1992 in Christchurch, but the captain took the brunt of the late fireworks himself.
Bowling on longer than he should have as he looked to convert his career-best overnight figures into a maiden five-wicket haul, the captain sent down 11 wicketless overs for 56, South Africa scored 28 off the last of them - 24 from Maharaj’s bat and four byes - to equal the Test record for most runs in an over.
England captain Joe Root paid tribute to the performances of Ollie Pope, who made 135 not out, and Dom Bess, who took five wickets in the first South African innings.
“It’s a great template for how we want to play our cricket moving forward, big first-innings score and drive the game from there,” he said at the post-match presentation.
“I think Ollie batted beautifully with (Ben) Stokesy - a brilliant partnership that put us in a commanding position.
“Then the way Bessy bowled was fantastic in that first innings. From that point on we always felt we were in control of things.
“Throughout this series we’ve had four guys under 25 making five-fors or hundreds, which is a great place to be.
“That’s something that we want to keep continuing to provide - an environment where that becomes possible and keep giving those guys confidence.”
Discussing his batting display, which included a 203-run partnership with Stokes, man of the match Pope said: “It was an amazing feeling but it wouldn’t have counted for much if we hadn’t won the game, so that’s the most important thing. To get over the line is an even better feeling.
“To bat with Stokesy is a privilege. He just keeps getting better and better.
“To see how he goes about building his innings and the tempo he plays at is awesome to watch. I was in a pretty good seat to watch another special innings from him.”