South Africa will have to return to Newlands on Sunday to score 41 runs to complete a series win over Pakistan after the hosts were bowled out for 294 in the last over of the third day of the second Test on Saturday.
Earlier in the third day, Dale Steyn and Kagiso Rabada struck early blows as Pakistan started their second innings.
Facing a first innings deficit of 254 runs, Pakistan were 37 for two at lunch, still needing 217 runs to make South Africa bat again.
Steyn had Imam-ul-Haq caught at third slip for six in the fourth over, with the batsman playing an ambitious drive. Rabada, coming as first change in the 11th over, dismissed Azhar Ali for six with his first delivery.
Azhar, who fell victim to short balls from Duanne Olivier in his first three innings of the series, went back on his stumps to a full delivery which cut back and kept low, trapping him leg before wicket.
Shan Masood, promoted to opening the batting in place of the struggling Fakhar Zaman, again looked the most competent of the Pakistan top-order batsmen as he reached 18 not out at lunch.
Earlier, Mohammad Amir took three wickets for 19 runs as South Africa were bowled out for 431.
The South Africans went for quick runs after resuming at 382 for six, adding 49 runs in 8.1 overs.
The left-armed Amir took the first three wickets of the morning and finished with four for 88.