Stokes claimed the last three wickets in the space of 14 deliveries deep into the concluding session of the match as England wrapped up a 189-run win.
Not only was it a first success for England at the famous Newlands ground since 1957, it was also an outstanding advert for the long-form story-telling that is five-day Test cricket – a format at this very moment in danger of being curtailed by administrators.
Starting the day chasing eight wickets to square the series at 1-1, Joe Root’s side still needed five after tea as the Proteas dug deep on a passive surface.
At various stages it seemed a doomed pursuit in sapping heat, but the tourists rallied triumphantly at the death with Stokes blowing away Dwaine Pretorius and Anrich Nortje with consecutive balls, then finishing off last man Vernon Philander with 8.2 overs remaining.
Allied to his six catches at second slip – a joint England record among non-wicketkeepers – and the swashbuckling 72 which bought England time in the second innings, and this completed yet another remarkable chapter for the sport’s hero of the hour.
South Africa had performed with admirable determination, Pieter Malan, Rassive van der Dussen and Quinton de Kock grinding out 342 deliveries between them on the day, but England matched their labours and held their catches.
After 137.4 overs in the dirt the celebrations – Chris Silverwood’s first as head coach – will taste all the sweeter. As for South Africa, they will rue abject lapses from captain Faf du Plessis and De Kock, who both conjured unprovoked dismissals to undermine the home cause.
James Anderson ended the day stiff, sore and seemingly carrying a niggle but started well by finding nightwatchman Keshav Maharaj’s edge.
For almost 18 overs Malan and Du Plessis successfully killed the momentum, Malan habitually leaving the ball unless it demanded attention and Du Plessis appearing ready for a long rearguard. Then a gift.
After nudging 19 from 56 deliveries the skipper shed all of his prior inhibitions as he knelt to sweep Dom Bess into the leg-side. Runs were essentially a non-factor with a distant theoretical target of 438 and Bess had caused precious few problems on a pitch offering only the most gentle turn.
Yet Du Plessis planted his ill-fitting shot straight to Joe Denly at square leg. England were delighted, surprised and relieved in equal share – not least Denly, taking his first catch since his jaw-dropping spill two Tests ago in Hamilton.
With spirits revived by a lunch total of 170 for four, Root’s decision to resume with Sam Curran paid off as the left-armer slanted one across Malan, finding some extra bounce and clipping the edge. Stokes held on low, concluding a brave stand comprising 84 runs and 231 dot balls.
Optimism spiked again but was gradually extinguished as Van der Dussen and De Kock chewed through another 169 deliveries before tea, taking the game to its final stanza.
With Anderson ailing Root invested heavily in spin, primarily in the form of 33 overs from Bess, but also in Denly’s leg-breaks and his own occasional offerings.
England needed inspiration or aberration and neither seemed to be forthcoming. Anderson, by now clearly unfit, managed two overs at the start of the final session – willing but ultimately unable to offer any more to the cause.
With the field crowding in, occupying a variety of unusual positions, De Kock cashed in on the gaps to reach 50. Perhaps sensing more cheap runs he swung hard at a Denly long-hop, ignoring more conservative measures, and picked out Zak Crawley at short mid-wicket.
Once again a mistake had changed the equation, leaving 25.2 overs to sweep up four remaining wickets. England burned five more of them before Root shuffled Anderson up from mid-on to leg-slip and drew instant gratification.
Stuart Broad bowled perfectly to the new plan, sliding one towards leg stump, and Van der Dussen unbelievably obliged as he fed the new fielder. After 17 runs and three and a quarter hours, his resistance was over.
England had 20 overs to take three wickets and in Stokes – hammering in relentlessly from the Wynberg End obliged. First Pretorius offered his outside edge and Root closed his fingers round a tricky catch, then Nortje was dramatically held at third slip by Crawley.
Parrying with one hand and plucking the falling ball with the other, he was smothered by the rest of a crowded cordon. There would be no hat-trick, but it had to be Stokes who applied the finishing touch, Philander prodding to Ollie Pope to conclude the drama.