Pakistan were 117 for six in their second innings at tea on Saturday, an overall lead of 91, in an extraordinary match in which 26 wickets had fallen for 457 runs.
Pakistan captain Inzamam-ul-Haq carried his team's hopes as the last remaining recognised batsman after Dale Steyn and Andrew Hall took two wickets each for South Africa. Inzamam was 19 not out.
South African wicketkeeper Mark Boucher earlier batted aggressively as South Africa squeezed out a slender first innings lead.
Boucher hit an unbeaten 40 as South Africa made 183 all out, a lead of 26, on a pitch which has helped pace and spin bowlers.
South Africa, resuming on 131 for five, were soon in trouble when Ashwell Prince was given out in the third over with only two runs added.
Prince was beaten by a Danish Kaneria googly and it seemed that wicketkeeper Kamran Akmal had missed his second stumping chance against the left-hander.
The ball bounced off Akmal's gloves and Yasir Hameed dived forward from silly point to catch it. Umpire Steve Bucknor gave Prince out caught to the batsman's undisguised surprise. Replays suggested Prince had missed the ball.
Two balls later nightwatchman Paul Harris edged Mohammad Asif to Younis Khan at second slip and South Africa had lost two wickets for two runs.
Andrew Hall was quickly caught behind off Kaneria for four but Steyn stayed with Boucher long enough for 43 runs to be added for the ninth wicket.
Boucher went on the attack after a quiet start in which only 18 runs were scored off the first 11 overs, hitting three fours, a two and a straight six in an over from Asif which cost 22 runs. The over included two no-balls.
Boucher slammed Kaneria over midwicket for six in the next over but the partnership was ended when Boucher tried to steal a single off the fifth ball of an over from Mohammad Sami, who replaced Asif.
Boucher dabbed the ball towards third man but Younis Khan chased it from slip and hit the stumps at the batsman's end to run out Steyn.
Boucher did not get a chance to face again because last man Makhaya Ntini was out first ball, leg before to Sami.
Boucher made his runs off 36 balls with five fours and two sixes.
Kaneria, bowling into a large bare area at the Wynberg end, took three for 44 and Asif three for 53.
Mohammad Hafeez did not look comfortable at the start of Pakistan's second innings but just when it seemed he was settling down, hitting two fours off Steyn, he sliced a catch to backward point off Steyn to be out for 10.
Steyn struck again after lunch when he swung a ball in to the left-handed Imran Farhat to win an lbw decision before Makhaya Ntini had Younis Khan caught behind without scoring.
First innings top-scorer Mohammad Yousuf looked threatening before he was bowled for 18 by a ball from Hall which held its line after a series of out-swingers. Hall then had Yasir Hameed caught at gully for 35.
Boucher pulled off a smart stumping to dismiss fellow wicketkeeper Kamran Akmal off left-arm spinner Harris.
Inzamam survived two difficult chances, a stumping off Harris on five when the ball turned sharply and bounced too high for Boucher to take cleanly, and a diving chance to Jacques Kallis at second slip off Hall four runs later.
Pakistan 157 and 117 for 6 (Yasir Hameed 35, Inzamam-ul-haq 19 n o; Andre Hall 2 for 23, Dale Steyn 2 for 32) Vs South Africa 183 (Graeme Smith 64, Boucher 40 n o, Kallis 28; Kaneria 3 for 44, Asif 3 for 53, Sami 2 for 41)