Robin Peterson and AB de Villiers hauled South Africa back into the game on the third day of the second Test against Pakistan at Newlands on Saturday.
South Africa, struggling on 139 for five overnight, racked up 326 thanks to 84 from Peterson and 61 by De Villiers. Pakistan then reached the close of play on 100 for three, an overall lead of 112 runs.
The visitors slumped to seven for two after openers Mohammad Hafeez and Nasir Jamshed were both removed for a duck.
Younus Khan (14) then became fast bowler Dale Steyn's second victim of the innings when he chopped the ball on to his stumps. But Azhar Ali (45 not out) and Misbah-ul-Haq (36 not out) settled Pakistani nerves with an undefeated fourth-wicket stand of 55.
The home team were hampered by the loss of paceman Morne Morkel who succumbed to a hamstring injury after having delivered 19 balls. He is unlikely to bowl again in the match.
Earlier, Peterson powered South Africa to within 12 of Pakistan's first-innings total after compiling his highest Test score.
His only previous Test half-century came against Bangladesh a decade ago.
Left-arm spinner Peterson has not had a great game with the ball but he showed his value as an all-rounder at number eight as he completely changed the momentum of the innings.
It was tough again early on for the batsmen, De Villiers and Dean Elgar adding 25 runs to South Africa's overnight score before the latter became off-spinner Saeed Ajmal's sixth wicket of the innings.
The left-handed Elgar flashed at a ball on 23 that gripped the surface and caught the edge, flying to Younus at slip.
Peterson joined De Villiers at the crease and the pair put on 46 for the seventh wicket in 11 overs.
De Villiers went to his 32nd Test half-century before debutant Mohammad Irfan claimed his first Test wicket, forcing the South African to spoon a catch to Umar Gul at mid-on when he had made 61.
Vernon Philander (22) then combined with Peterson for a partnership of 67 before the former was bounced out by Irfan with a well-directed short ball that was edged to Jamshed at point.
Steyn was dismissed for 10 before Peterson was the last to go. He tried to hit a six off part-time spinner Hafeez but succeeded only in picking out Gul on the long-on boundary.
Ajmal finished with six for 96 while Irfan picked up three for 86.
South Africa are 1-0 up in the three-match series.
Photograph: Stringer/Reuters