Pakistan were 103 for two in their second innings, one run behind, after South Africa lost their last six wickets for 61 runs.
Ashwell Prince made his sixth Test century as he and Herschelle Gibbs put on 213 but Prince's dismissal in the over before lunch started a collapse which restricted South Africa's first innings lead to 104.
All-rounder Jacques Kallis claimed the wickets of Mohammad Hafeez and Yasir Hameed before the close but Imran Farhat and Younis Khan added an unbeaten 45 to get the tourists close to parity.
"We would have liked to have a lead of 150 or 200," said Gibbs.
"We've got a lot of work to do on Sunday but we're confident we can chase whatever we have to chase to win."
Prince made 138 before he was stumped off Danish Kaneria.
Four more wickets fell quickly after the interval before Shaun Pollock and Makhaya Ntini added 26 for the last wicket to take the lead beyond 100.
Opening bowler Mohammad Asif finally dismissed Ntini, caught at second slip, to finish with five for 89, his third five-wicket haul in a seven-Test career.
Gibbs was part of the post-lunch collapse, leg before wicket to Rana Naved-ul-Hasan for 94, falling short of his first Test century in two years.
The left-handed Prince, who has made all his Test hundreds within the space of two years, batted fluently but survived a close lbw appeal by Mohammad Asif on 98 and an appeal for caught and bowled by Shahid Nazir when he had 126.
In the latter incident, Prince mistimed a drive and Nazir picked up the ball low down in his follow through. Nazir threw the ball up in triumph but Prince stood his ground. Umpire Steve Bucknor consulted with square leg umpire Billy Doctrove and the appeal was referred to television umpire Karl Hurter.
The replays were inconclusive although it seemed Nazir might have caught the ball on the half-volley and Prince was given not out.
Pakistan's bowlers were largely lacklustre before lunch on a hot, cloudless day but Kaneria followed up the wicket of Prince with two more to finish with three for 97, while Naved-ul-Hasan improved otherwise disappointing figures by taking two wickets in nine balls.
Prince's innings was ended when he went down the pitch and missed a ball from leg-spinner Kaneria.
With an easy stumping chance, Akmal missed with his first pass at the stumps before knocking off the bails at the second attempt. Prince almost got back but was given out on a television replay decision. He batted for 347 minutes, faced 213 balls and hit 19 fours.
Gibbs had not scored a Test hundred since he reached three figures against England in Johannesburg on January 15, 2005.
Naved, who had conceded 72 runs in 12 overs, trapped Gibbs lbw with the first ball of a new spell. Gibbs batted for 279 minutes, faced 205 balls and hit 15 boundaries.
Hafeez and Farhat put on 41 for Pakistan's first wicket before Kallis, the fourth bowler used, struck with his third ball when Hafeez was caught at first slip for 15. Kallis followed up by having Hameed caught behind for nine.
It was reported that leading Pakistan batsman Mohammad Yousuf, who missed the first Test because his wife was having a baby, would be in South Africa in time for the remaining two Tests following the birth of a daughter Friday.