During the interval, England made a clear decision to break the shackles, and although Jonny Bairstow was caught at deep backward square-leg to give Olivier a third victim, Moeen was able to continue the assault thanks to Elgar's second drop - this time off Maharaj.
The all-rounder's unbeaten 69 helped haul Joe Root's men to an nearly unassailable position on 224-8, 360 runs ahead, as they seek to seal a 3-1 series win.
Ali, coming in at No. 8, counterattacked convincingly, hitting eight fours and three sixes in his 67 from just 59 balls.
Reflecting on his innings with Sky Sports' Ian Ward in The Zone, Ali said: "I was really getting going - we needed a bit of momentum and it came off for me, even though I had a couple of chances". But I just want that last wicket, I don't care who gets it. That's a lead of 360‚ or one run fewer than South Africa's highest total in each of their other half-dozen innings in the series.
After Roland-Jones departed, top-edging as he tried to pull Rabada, Broad joined Moeen and the pair will resume on Monday after rain cut play short in the final hour.
Iran`s Hassan Rouhani sworn in for second term
Rouhani will be sworn in on Saturday and then have two weeks to present his cabinet to parliament for a vote of confidence. The diplomat also said presidents of seven countries had arrived Iran by Thursday night to take part in the ceremony.
It was paceman Morne Morkel who got the early breakthroughs, however, striking twice before lunch.
Alastair Cook went in the seventh over, attempting a cover drive, but his thick edge flew to Theunis de Bruyn, who comfortably pocketed the catch at gully.
The seamer soon had his second, when Tom Westley also fell driving - substitute Aiden Markram taking the catch in the gully.
Another individual who may find his involvement with England end with the series, temporarily at least, is Keaton Jennings.
Olivier had his tail up, causing problems with his clever right-arm medium-fast deliveries and, after troubling Stokes outside the off-stump on several occasions, got his reward when the England batsman edged to skipper Faf du Plessis at first slip.
Anderson recorded his career best figures of four for 33 from the newly-named James Anderson End, which included a game-breaking spell of three for six in 20 balls at to leave him one away from a maiden Test five-wicket haul on his home ground.