Vernon Philander took three wickets in three overs before Pakistan tailenders Tanvir Ahmed and Saeed Ajmal frustrated South Africa on the second day of the second Test at Newlands on Friday.
Pakistan were bowled out for 338 at lunch after Tanvir (44) and Ajmal (21 not out) had put on 64 for the ninth wicket after Philander's early strikes raised the home side's hopes of wrapping up the innings quickly.
Philander, who took five for 59, struck with his first ball of the day when Asad Shafiq was caught at first slip without adding to his overnight score of 111. Shafiq batted for 308 minutes and faced 230 balls.
Sarfraz Ahmed, the other overnight batsman, fell in Philander's next over when Alviro Petersen dived full length to his right to hold a good catch at third slip. Sarfraz made 13.
Umar Gul was leg before wicket without scoring as Philander completed his ninth five-wicket haul in Test matches.
But Tanvir and Ajmal went for their strokes, with Tanvir in particular hitting out aggressively as he made 44 off 59 balls with four fours.
South Africa suffered a blow when fast bowler Morne Morkel left the field after bowling three balls of his 21st over with what was described as a tight left hamstring.
Tanvir fell shortly before lunch when he hit left-arm spinner Robin Peterson to Philander at deep mid-off, with last man Mohammad Irfan following in the next over when he was bowled by Peterson, going for a big hit.