All-rounder Stokes, fresh from a hundred in England's 239-run victory in the third Test at The Oval, was leading a revival with the bat.
But fast bowler Rabada struck with the new ball in the penultimate over of the day when a full-length delivery, which surprised Stokes, smashed into the base of the stumps and bowled the left-handed batsman for 58.
Rabada, banned from the second Test for swearing at Stokes in the series opener, yelled in joy.
He finished the day with figures of two for 52 in 18 overs, but the worth of South Africa's efforts with the ball will only become fully apparent when they bat.
Jonny Bairstow, who might have fallen for four, was 33 not out and nightwatchman Toby Roland-Jones unbeaten on nought at the close.
For the tenth successive Test, England captain Joe Root made a fifty.
But only two of those innings have yielded hundreds and Root, who has previously acknowledged his 'conversion rate' as a failing in his otherwise impressive game, was out for 52 on Friday.
England were unchanged from the side that triumphed in The Oval's 100th Test, a result that left Root on the brink of a win in his first series as England captain at 2-1 up with one to play.
But South Africa recalled seamer Duanne Olivier and batsman Theunis de Bruyn after pacemen Vernon Philander and Chris Morris were both ruled out with lower back strains.
Root again won the toss and batted.
But struggling opener Keaton Jennings fell for 17.
The South Africa-born left-hander, under pressure for his place after just one fifty in nine Test innings since a century on debut against India in December, was caught behind by schoolboy team-mate Quinton de Kock off Olivier.
The Essex duo of Alastair Cook (46) and Tom Westley (29) both exited after lunch with England on 92.
Cook got a thin edge driving at left-arm spinner Keshav Maharaj and was caught behind.
Westley, fresh from a second-innings fifty on debut at The Oval, nicked a good length Rabada ball, with de Kock holding a superb diving catch for his 100th Test dismissal.
Dawid Malan was looking for a big score after managing just 11 runs during his Test debut at The Oval.
Morne Morkel, however, saw off Malan, born in London but raised in South Africa, when the Middlesex left-hander edged a drive to Proteas captain Faf du Plessis at second slip.
Morkel has repeatedly bowled well this series without proper reward.
Another example of his bad luck came when Root edged the towering quick on 40, only for de Kock to inexplicably remain rooted to the spot for what was his catch.
De Kock's anguished expression as the ball went through the slips for four spoke volumes.
Fortunately for de Kock, it was not an expensive error, with Olivier the beneficiary of a misjudgement by Root, lbw, to end a 101-ball stay.
During his innings Root, at 26 years and 217 days, became the third youngest player after Indian legenf Sachin Tendulkar (25 years, 301 days) and Cook (26 years and 10 days) to score 5,000 Test runs.
There was confusion when Bairstow appeared to be caught for four off Maharaj only for umpire Kumar Dharmasena to eventually ask for a review of Dean Elgar's slip catch.
Despite seemingly insufficient evidence to change an on-field 'soft signal' of out, third umpire Joel Wilson ruled in England's favour.
Stokes completed an 89-ball fifty before Rabada's late strike.
First Published: August 4, 2017, 11:47 PM IST