Pakistan face an uphill battle to save the first test after closing the fourth day on 109 for two after being set a formidable winning target of 450 by South Africa on Monday.
Jacques Kallis and Hashim Amla both hit centuries in compiling a record third-wicket stand of 242 for South Africa against Pakistan, allowing the tourists to declare on 318 for two in their second innings.
Pakistan made a solid start and they reached 41 before Mohammed Hafeez, who scored a breezy 34 off 47 balls, edged a delivery from paceman Dale Steyn to first slip.
Taufeeq Umar (22) and Azhar Ali (37 not out) then defied their opponents for 18.2 overs with a second-wicket stand of 34 before Umar was caught at first slip off a ball from Johan Botha.
Ali and Younus Khan (11 not out) saw their team to stumps although Ali suffered a painful blow on his thumb from a Steyn bouncer.
Kallis and Amla took full advantage of a benign pitch and an increasingly dispirited-looking Pakistan bowling attack missing a seamer after left-armer Wahad Riaz picked up a side strain on the first day.
Amla, who brought up his 11th test ton off 190 deliveries, ended not out on 118 off 225 balls, striking 10 fours during his knock.
Kallis was equally impressive as he recorded his 36th test century to finish unbeaten on 135 off 218 balls, while his innings was highlighted by eight fours and four sixes.
Amla and Kallis scored 77 runs off 18 overs after lunch as the pair went in search of quick runs to set up the declaration.
South Africa made 380 in their first innings before Pakistan collapsed to be all out for 248 in reply.
South Africa first innings 380
Pakistan first innings 248
South Africa second innings (overnight 139-2):
A. Petersen lbw b Rehman 26
G. Smith lbw b Ajmal 34
H. Amla not out 118
J. Kallis not out 135
Extras (b-1, w-1, lb-2, nb-1) 5
Total (two wickets declared; 95 overs) 318
Fall of wickets: 1-47, 2-76,
Bowling: Gul 18-0-73-0, Younus 3-0-15-0, Rehman 36-5-105-1, Hafeez 11-3-20-0, Ajmal 27-2-102-1.
Pakistan second innings:
M. Hafeez c Botha b Steyn 34
T. Umar c Kallis b Botha 22
A. Ali not out 37
Younis not out 11
Extras (b-4, lb-1) 5
Total (two wickets; 41 overs) 109
Fall of wickets: 1-41, 2-75
Bowling: Steyn 10-1-49-1, Morkel 9-3-17-0, Harris 8-2-11-0, Botha 14-4-27-1