Chris Morris gave the opener some useful support in making 24 but he was dismissed on the stroke of lunch, pushing at a delivery from Moeen and was well caught by a diving Stokes at first slip.
Broad made the breakthrough as he smashed through the defences of opener Heino Kuhn, while Toby Roland-Jones added to his five-wicket haul in South Africa's first innings to snare the pivotal wicket of Hashim Amla, caught by skipper Joe Root in the slips.
That left then 178 runs behind England's first innings 353, which featured Ben Stokes's 112 and former captain Cook's 88.
With the four-match series level at 1-1, South Africa must try to bat through three sessions to secure a draw or an unlikely victory on day five.
Then came the actual review, and what a decision it was as Temba Bavuma, a thorn in the hosts' side a few times on this tour, was dismissed after a Toby Roland-Jones delivery cannoned into his pads inside the line of off stump by the smallest of small margins to spark what should be England's march to victory.
England needed six wickets on the final day to regain the advantage with one match to come at Old Trafford after setting the Proteas a world-record 492 to win the 100th Test at the famous London ground.
Philander followed next ball, shouldering arms in an nearly identikit dismissal to that of South African skipper Faf du Plessis, who had been trapped first ball by Ben Stokes the previous day.
Smith, who toured there three times for two famous series wins during his 117-Test career, said the out-of-form Jennings could find Australia "quite a scary place".
Left-hander Jennings was on 33 when given out lbw to fast bowler Kagiso Rabada but his review of umpire Joel Wilson's decision showed the ball had pitched just outside his leg stump.
It was England's first hat-trick against South Africa since 1958.
Next ball, Vernon Philander, in the mould of his captain Faf du Plessis, played no shot to a ball that also nipped back at him and was plumb LBW.
James Anderson (2-16) deepened the in-roads in conditions flawless for seam bowling before South Africa - needing 154 to avoid the follow-on - closed on 126-8, 227 behind, despite a 53-run stand between Temba Bavuma (34 not out) and Kagiso Rabada (30).
Meanwhile an elated Ali said of his hat-trick ball: "I was very confident it was out".