South Africa opener Aiden Markram hit a century to help the Proteas recover from Pakistan medium pacer Hasan Ali's double strike on the fifth and final day in the second Test on Monday.
Markram drove the last ball before lunch from Fawad Alam to wide mid-on for a single to reach his fifth Test century - the first outside South Africa.
Temba Bavuma hit 44 not out as the pair guided South Africa to 219-3, needing another 151 runs in pursuit of a daunting 370-run target in a possible 65 overs.
Markram, who has so far hit 12 boundaries and three sixes, added 84 runs for the fourth wicket with Bavuma after Rassie van der Dussen fell on his overnight score of 48 and Faf du Plessis for five.
Both teams had been involved in a keen battle for victory as Pakistan eyes a first series win over South Africa since 2003 while the tourists pin hopes on their batsmen to get the highest run chase at this ground.
No team has ever chased more than the 369 runs that Australia achieved against Pakistan in a 1999 Test at Hobart.
The best chase at Rawalpindi Cricket Stadium in ten previous Tests is 200 scored by Sri Lanka in 2000.
Resuming on 127-1, South Africa saw Dussen bowled off a beautiful inswinger by Hasan -- only the third ball of the day - while Du Plessis was leg-before to the same bowler in the fifth over of the morning.
Hasan has figures of 2-46.
It capped a miserable series for the experienced Du Plessis who managed just 55 in four innings.
Pakistan won the first Test in Karachi by seven wickets.