Johannesburg: Pakistan were set to make 381 to win the third and final Test against South Africa at the Wanderers Stadium on Sunday.
Quinton de Kock hit 129 before South Africa were bowled out for 303 in their second innings on the third day.
Medium-pacer Faheem Ashraf and leg-spinner Shadab Khan both took three wickets.
South Africa, first innings, 262
Pakistan, first innings, 185
South Africa, second innings
(overnight 135-5)
D. Elgar c Sarfraz Ahmed b Mohammad Amir 5
A. Markram c Sarfraz Ahmed b Mohammad Abbas 21
H. Amla c Sarfraz Ahmed b Hasan Ali 71
T. de Bruyn c Asad Shafiq b Faheem Ashraf 7
Zubayr Hamza lbw b Faheem Ashraf 0
T. Bavuma c Sarfraz Ahmed b Shadab Khan 23
Q. de Kock c Hasan Ali b Shadab Khan 129
V. Philander lbw b Mohammad Amir 14
K. Rabada c Shadab Khan b Faheem Ashraf 21
D. Steyn not out 0
D. Olivier c Sarfraz Ahmed b Shadab Khan 1
Extras (b2, lb6, nb1, w1) 11
Total (80.3 overs) 303
Fall of wickets: 1-24 (Elgar), 2-29 (Markram), 3-45 (De Bruyn), 4-45 (Hamza), 5-93 (Bavuma), 6-195 (Amla), 7-223 (Philander), 8-302 (De Kock), 9-302 (Rabada)
Bowling: Mohammad Amir 20-2-56-2, Mohammad Abbas 18-3-73-1 (1w), Hasan Ali 17-1-83-1, Faheem Ashraf 14-3-42-3 (2w), Shadab Khan 11.3-0-41-3
Match situation: Pakistan need 381 runs to win
Toss: South Africa
Umpires: Sundaram Ravi (IND), Joel Wilson (WIN)
TV umpire: Bruce Oxenford (AUS)
Match referee: David Boon (AUS)
Former Karachi mayor Waseem Akhtar says his daughter has come from Houston, US to take part in event
Babar Azam and Mohammad Rizwan remain not-out with scores of 31 and nine respectively
Ayub's test reports sent to specialists in London for further advice on treatment
Rickelton scores 176* while Bavuma smashes ton to put their side in control against Pakistan
Left-handed batsman taken off the field after medical care, sent to nearby hospital for additional testing
"I think he might just pull the plug at the end of this Test," says ex-India coach