South Africa lost momentum after a brisk start to their second innings but will take a lead of 323 runs over Pakistan into the final day of the second and final Test at the Sheikh Zayed Stadium.
Hashim Amla, who became the third batsman after India's Sachin Tendulkar and Virender Sehwag to score a thousand Test runs a calendar year, hit a run-a-ball 62 as South Africa reached 173 for four at the close on Tuesday.
Amla's departure in the sixth over after tea resulted in a loss of momentum with slow left-armer Abdur Rehman and off-spinner Mohammad Hafeez applying the brakes with economical spells.
Pakistan's tailenders had earlier frustrated South Africa who had dismissed Misbah-ul-Haq (77) with the first ball of the day, trapped lbw trying to drive a Dale Steyn in-swinger.
Rehman made his highest Test score of 60 as Pakistan surpassed the follow-on mark of 385 before being bowled out for 434.
Rehman put on 59 with Tanvir Ahmed (30), who hit some swashbucking drives, in an entertaining and crucial ninth-wicket stand.
The first Test in Dubai was drawn.
Scoreboard:
South Africa first innings: 584 for 9 (declared)
Pakistan first innings
M Hafeez lbw b Steyn 2
T Umar c Amla b Kallis 43
A Ali c Smith b Steyn 90
Younis c Amla b Steyn 14
Misbah-ul-Haq lbw b Steyn 77
A Shafiq c Kallis b Harris 61
A Akmal c Amla b Harris 17
A Rehman lbw b Botha 60
U Gul lbw b Harris 21
T Ahmed c Prince b Morkel 30
M Sami not out 2
Extras (b-5, lb-8, w-2, nb-2) 17
Total (all out, 144.1 overs) 434
Fall of wickets: 1-2, 2-119, 3-153, 4-156, 5-263, 6-309, 7-317, 8-353, 9-412, 10-434.
Bowling: Steyn 30-8-98-4 (1-w), Morkel 33-13-94-1 (2-nb, 1-w), Kallis 21-6-77-1, Botha 14.1-3-54-1, Harris 46-17-98-3.
South Africa second innings
A Petersen c Younis b Rehman 35
H Amla b Rehman 62
AB de Villiers lbw b Rehman 25
J Kallis c Umar b Hafeez 10
A Prince not out 27
M Boucher not out 13
Extras (nb-1) 1
Total (four wickets, 49 overs) 173
Bowling: U Gul 4-0-25-0, T Ahmed 3-1-15-0, A Rehman 21-1-73-3, M Sami 5-0-28-0, M Hafeez 16-4-32-1.