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.
"I am pretty happy. I think Pakistan are one of the better test attacks and to score runs against them is very satisfying," the 33-year-old Peterson told a news conference.
"I think the match is pretty evenly poised now."
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.
The 35-year-old Ajmal finished with six for 96 while Irfan picked up three for 86.
"Ajmal is a genius with the ball, he has four different deliveries an over. But I thought even with the lower order, the longer we batted against him the more we got used to the way he bowled," Peterson said.
"All the guys will now go away and devise some game-plans against him. We know he will be their main weapon and we don't want to chase much over 250 in the final innings against him."
South Africa are 1-0 up in the three-match series.