South Africa opener Sarel Erwee hit 73 to put the Proteas in charge, a 27-run advantage with seven first-innings wickets.
However, as part of South Africa’s decline from 160-2 to 210-6, Stokes bounced out Erwee and then had Rassie van der Dussen lbw.
Marco Jansen and Keshav Maharaj, who shared a crucial partnership of 72 from only 75 balls, halted the rot.
READ MORE: Kagiso Rabada & Anrich Nortje rip through England before Lord’s rain
Stokes had Maharaj hook to Matthew Potts for 41 as England seemed worn out, and the game was slipping away, leaving Jansen undefeated on 41 and South Africa 289-7, a 124-point lead.
Ollie Pope was dismissed for 73 after England had been knocked out for 165.
Pope was the first of Kagiso Rabada’s three wickets to fall, and the fast bowler was outstanding in taking 5-52.