Pakistan were 108 for one at close of play on the fourth day of the second test, chasing an improbable victory target of 457 after centuries from South Africa captain Graeme Smith and Jacques Kallis.
At the crease, Kamran Akmal was on 49 and Younis Khan had made 48 as Pakistan fought hard after the early loss of opener, Salman Butt for six.
South Africa declared on 305 for four at tea leaving Kallis unbeaten on 107 for his third century of the series.
He enjoyed a third-wicket stand of 207 from 431 balls with Smith (133).
South Africa won the first Test by 160 runs and could wrap up the series 2-0.
Beginning their second innings after tea, Pakistan lost Butt in the sixth over when substitute Shaun Pollock took a smart catch at third slip off Makhaya Ntini's bowling.
But on a pitch which is playing up and down, Younis and wicketkeeper Akmal fought back with some courageous batting and kept the score moving with some good shots.
Scorecard
South Africa (1st innings): 357 (Prince 63, Kallis 59, Boucher 54)
Pakistan (1st innings 206): (K Akmal 52)
South Africa (2nd innings):
G Smith c sub Hameed b Kaneria 133
H Gibbs c Akmal b Gul 16
H Amla b Rehman 17
J Kallis not out 107
A Prince b Rehman 11
AB de Villiers not out 8
Extras: (nb-1, b-12) 13
Total: (four wickets declared; 110.3 overs) 305
Did not bat: Mark Boucher, Paul Harris, Dale Steyn, Andre Nel, Makhaya Ntini.
Fall of wickets: 1-34, 2-66, 3-273, 4-290.
Bowling: Mohammad Asif 4-1-14-0, Umar Gul 16-3-48-1 (nb-1), Danish Kaneria 44.3-11-99-1, Abdul Rehman 42-7-112-2, Younis Khan 4-0-20-0
Pakistan (2nd innings):
Salman Butt c sub b Ntini 6
Kamran Akmal not out 49
Younis Khan not out 48
Extras: (b-2, lb-3) 5
Total: (one wicket, 31 overs) 108
To bat: Mohammad Yousuf, Inzaman-ul-Haq, Shoaib Malik, Misbah-ul-haq, Umar Gul, Mohammas Asif, Danish Kaneria, Abdur Rehman
Fall of wicket: 1-15
Bowling: Steyn 7-2-25-0, Ntini 6-2-24-1, Kallis 2-0-5-0, Nel 6-1-37-0, Harris 10-5-12-0.