Robin Peterson and Dale Steyn led a South African fightback which left the second Test against Pakistan evenly poised at the end of the third day at Newlands on Saturday.
Pakistan were 100 for three in their second innings at the close, a lead of 112.
Peterson hit 84 to enable South Africa to get within 12 runs of Pakistan's first innings total of 338 and Steyn bowled at blistering pace to take two wickets as Pakistan lost their first three second innings wickets for 45 runs.
At that stage South Africa were slightly on top but Azhar Ali and captain Misbahul Haq shared a largely cautious unbeaten partnership of 55 to see Pakistan through to the close without further loss.
South Africa were hampered by a recurrence of a hamstring injury to Morne Morkel, who left the field after bowling one ball in his second spell.
He had to stop bowling because of the same injury in the first innings as well and seems unlikely to take the ball again in the match.
Peterson led a fighting performance by South Africa's lower-order batsmen as they recovered from an overnight 139 for five to reach 326 all out.
Pakistan's first innings lead of 12 runs was soon shown to be negligible as Steyn and Vernon Philander both took wickets in their first overs.
Mohammad Hafeez was comprehensively trapped leg before wicket by a ball which swung into him. After the briefest of consultations with opening partner Nasir Jamshed he walked off without seeking a review.
In the next over Jamshed fell in similar fashion to Philander.
After discussion with new partner Azhar he started to indicate he wanted a review but appeared to be told by umpire Steve Davis that he had taken longer than the 15 seconds allowed.
Replays showed the ball would have clipped his bails so the decision would have been upheld.
Azhar and first innings centurion Younis Khan battled through some testing bowling against Steyn, Philander and Morkel.
Bowling downwind in his second spell, Steyn was timed at more than 146kmh and troubled both batsmen before Younis, forced on to the back foot, chopped the ball into his stumps.
After being dismissed without scoring in the first innings, Misbah took 18 balls to score his first runs in the second innings.
Scoring slowed to a crawl, with left-arm spinner Peterson conceding only four runs in his first eight overs.
But Misbah gained in confidence, three times hitting Peterson for six as he advanced to 36 not out. Azhar was unbeaten on 45.
Overnight batsmen AB de Villiers and Dean Elgar started South Africa's recovery when they took their sixth-wicket stand to 55 before Elgar was caught at slip off Saeed Ajmal for 22.
At that stage off-spinner Ajmal had taken all six wickets but he had no further success, finishing with six for 96.