Earlier Robin Peterson and Dale Steyn led a South African fightback which left the match evenly poised.
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.
Team manager and doctor Mohammad Moosajee said he was a doubtful starter for the third and final Test starting at Centurion on Friday.
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.
"I had a good chat to a few people about how we were going to play Saeed Ajmal," he said.
Off-spinner Ajmal took all five wickets on Friday and finished with six for 96.
"Saeed is a genius of spin bowling," added Peterson.
"He can bowl about four different deliveries an over. Even if you can pick all of them it is tough to have that absolute concentration all the time. We had our hands full but the more overs he bowled the easier it became."
Both Peterson and Pakistan bowling coach Mohammad Akram felt that a target of around 250 was a benchmark.
"We don't want to chase more than 300," said Peterson. "Hopefully it will be under 250."
Akram said: "Anything over 250 will be a really good total."
He said although Pakistan were disappointed that South Africa's lower order had made so many runs the team was in a good position.
"South Africa are a good side. You expect you will get serious resistance. We are still in the game. After (defeat in the first Test in) Johannesburg, the boys are really upbeat about where we are today," added Akram.
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 while, in the next over, Nasir Jamshed fell in similar fashion to Philander.
Azhar Ali 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 reached 36 not out while Ali 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 Ajmal for 22.
At that stage off-spinner Ajmal had taken all six wickets.
The left-handed Peterson shrugged off a poor run of batting form which had yielded just 15 runs in his previous seven international innings, including five noughts.
He went to his second Test fifty off 73 balls and went on to pass his previous best score of 61 against Bangladesh in Dhaka 10 years ago.
De Villiers fell to Mohammad Irfan for 61 in the first over with the second new ball after a seventh wicket stand of 46 with Peterson.
But Peterson and Philander (22) added an innings-best 67 for the eighth wicket.
The last two wickets brought another 49 runs before Peterson was last out, caught on the long-on boundary off Hafeez.
Peterson made his 84 runs off 106 balls with 15 fours.
The tall Irfan, playing in his first Test, took three for 86 and troubled the batsmen with steep bounce.
COMMENTS (7)
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ
I love cricktr playing and watching.and i wish pakistan playing good and win all searies against any country specily beat to india in every field.
I don't know why on earth Sarfraz and Tanvir have been selected on this tour, it looks they wanted to fill the numbers from Karachi. Sarfraz keeping is as horrendous as you can ever get, he missed two catches and gave loads of byes, and his batting is below par at test level.
I K only focus on political campaign and elections.
will lose.
de Villiers is NOT SA captain. Smith is.
Best bowling attack would have been Irfan Gul Ajmal and Rehman...and if fit Junaid is better than Gul....I fail to understand how two reserves who were not even part of actual selected players (Rahat and Tanveer) came on and got selected ahead of better options....then what about Sarfraz...??? What Adnan did wrong to get dropped and what Sarfraz has done ...??? 22 byes....in one inning and no score to show...dropping devileers also..... if selection was right then we would have won this series now it seems 3-0 to SA
who decided to select this Tanvir Ahmed? his every bowl is perhaps slower then the slower balls of our more accomplished bowlers. Bring back Wahab Riaz then if anything if you have to play a bowler who grunts like he is bowling 160KPH when he is only bowling 115KPH!