Saeed Ajmal took five wickets to leave South Africa struggling in reply to Pakistan's 338 in the second Test in Cape Town.
Ajmal's haul of 5-41 during an unchanged 25-over spell reduced South Africa to 139-5 in their first innings, still 199 behind, at stumps on day two.
The off-spinner used the review system to send both Graeme Smith (19) and Hashim Amla (25) on their way lbw.
And Jacques Kallis' dismissal for two was upheld in controversial circumstances. Umpire Steve Davis appeared to give Kallis out caught at short-leg, a decision the veteran batsman immediately reviewed.
Replays confirmed there was no inside edge but instead showed he was out lbw, albeit the ball was only flicking leg stump.
Kallis refused to walk at first and Davis was prompted to have a further discussion with third umpire Billy Bowden before the lbw verdict was finally confirmed.
Faf du Plessis (28) edged to slip four overs later as South Africa slumped to 109-5 before AB de Villiers (24no) and Dean Elgar (11no) forged an unbroken sixth-wicket stand of 30 during the final hour of the day.
Earlier, Vernon Philander (5-59) completed the ninth five-wicket haul of his 15-Test career as Pakistan went from 253-5 at the start of the day to 338 all out.
Asad Shafiq, on 111 overnight, edged his first delivery of the day from Philander through to wicketkeeper De Villiers.
Philander also accounted for Sarfarz Ahmed (13), thanks to a stunning diving catch low to his right from Alviro Petersen at third slip, and Umar Gul lbw for a duck before Tanvir Ahmed (44) and Ajmal (21no) combined in a 64-run stand for the ninth wicket to push the score beyond 300.
Tanvir was eventually caught by Philander at mid-off after he thrashed at a delivery from left-arm spinner Robin Peterson (2-94) before seven-foot debutant Mohammad Irfan was trapped lbw by the same bowler to force a slightly early lunch.