Pakistan's Younis Khan and Faisal Iqbal shared a big stand to hold up South Africa's push for victory in the first Test after Jacques Kallis hit his second century of the match on the fourth day on Thursday.
Younis (93 not out) and Faisal (44) put on 114 for the third wicket after Pakistan lost their openers quickly but left-arm spinner Paul Harris struck before the close to leave Pakistan on 146 for three, still needing 278 more runs for victory.
South Africa had declared before tea to set the hosts a target of 424.
Harris had Faisal caught by Kallis at slip with a sharp turning delivery.
Younis was in a punishing mood, racing to 93 from 99 balls with 14 fours and a six.
He and Faisal mixed caution with several glorious strokes after paceman Dale Steyn had removed Mohammad Hafeez (1) and Salman Butt (3).
Kallis, who scored 155 in the first innings, struck an unbeaten 100 in the second as South Africa declared on 264 for seven.
Scorecard
South Africa (1st innings): 450 (Jacques Kallis 155, AB de Villiers 77, Hashim Amla 71; Abdul Rehman 4-105)
Pakistan (1st innings): 291 (Shoaib Malik 73, Paul Harris 5-73)
South Africa (2nd innings):
Graeme Smith c Akmal b Rehman 25
Herschelle Gibbs c Faisal b Kaneria 18
Hashim Amla st Akmal b Rehman 0
Jacques Kallis not out 100
Ashwell Prince b Kaneria 45
AB de Villiers b Rehman 1
Mark Boucher c Misbah b Kaneria 29
Andre Nel c Misbah b Rehman 33
Paul Harris not out 1
Extras: (b-10, lb-2) 12
Total: (for 7 wickets declared, 89 overs) 264
Fall of wickets: 1-41, 2-43, 3-43, 4-131, 5-132, 6-188, 7-251
Bowling: Mohammad Asif 6-1-14-0, Umar Gul 12-1-35-0, Abdul Rehman 38-6-105-4, Danish Kaneria 28-3-85-3, Mohammad Hafeez 5-0-13-0.
Pakistan (2nd innings):
Mohammad Hafeez b Steyn 1
Salman Butt c Amla b Steyn 3
Younis Khan batting 93
Faisal Iqbal c Kallis b Harris 44
Mohammad Asif batting 1
Extras: (lb-4) 4
Total: (for 3 wickets, 33 overs) 146
To bat: Misbah-ul-Haq, Shoaib Malik, Kamran Akmal, Umar Gul, Danish Kaneria, Abdul Rehman.
Fall of wickets: 1-1, 2-20, 3-134
Bowling: Makhaya Ntini 6-1-19-0, Dale Steyn 9-1-44-2, Andre Nel 7-2-35-0, Paul Harris 9-1-24-1, Graeme Smith 2-0-20-0.