A brilliant century from Quinton de Kock put South Africa on course for a series whitewash as they set Pakistan 381 to win the third Test.
Having reached his fourth Test hundred, De Kock was eventually dismissed for 129 as South Africa were bowled out for 303 midway through the afternoon session.
Dale Steyn (2-37) then removed Pakistan openers Imam-ul-Haq (35) and Shan Masood (37) after the pair had given the tourists a solid start to their chase and Duanne Olivier (1-41) continued his fine form in the series with the wicket of Azhar Ali (15).
Asad Shafiq (48no) and Babar Azam (17no) took Pakistan to 153-3 at the close in Johannesburg, still 228 runs short of their target, while South Africa require another seven wickets for victory.
The day began with De Kock and Hashim Amla (71) at the crease and they frustrated the Pakistan bowlers for much of the first session, both passing 50 in a stand of 102 before Hasan Ali (1-83) found Amla's edge with a ball that diverted off a crack in the pitch.
De Kock raced into the nineties with a flurry of boundaries and after being delayed for a short time on 99, he reached three figures with a crisp, straight drive for four.
The wicketkeeper-batsman was the eighth man to fall, holing out off Shadab Khan (3-41), and the Proteas added just one more run before they were bowled out.
Imam and Masood made a positive start as Pakistan set off in pursuit of an imposing target but both were eventually undone by Steyn, caught behind, as the seamer moved past Richard Hadlee in the list of all-time Test wicket-takers with his first and up to joint-eighth, level with Rangana Herath and Stuart Broad on 433, with his second.
Olivier then ousted Azhar with a sharply-rising bumper, taking him to 22 wickets in the series and leaving Shafiq and Babar to see Pakistan through to stumps.
Watch day four of the third Test between South Africa and Pakistan from 7.55am, Monday on Sky Sports Cricket.