South Africa still need 243 runs but have nine wickets in hand as they look to complete the highest chase by a visiting team in Pakistan after Mohammad Rizwan's unbeaten century set them a mammoth target.
Pakistan had begun day four of the second Test in Rawalpindi on 129-6 in their second innings, meaning a lead of 200.
However, Rizwan's 115 not out helped them build that to 369, leaving the Proteas with an arduous task that Aiden Markram and Rassie van der Dussen attacked impressively in the final session.
Markram and Van der Dussen reached stumps unbeaten on 59 and 48 respectively as South Africa moved to 127-1 in reply by the close, their efforts keeping an excellent Test in the balance and keeping the tourists' hopes of squaring the two-match series at 1-1 intact.
Rizwan had resumed on 28 and ensured South Africa would not succeed in keeping the lead under 300, his maiden Test century potentially a match-winning one.
His fluent innings comprised of 15 fours and continued a theme of the series as Pakistan's tail provided stubborn resistance once again.
The wicketkeeper-batsman put on a stand of 53 with Yasir Shah (23) and then a ninth-wicket partnership of 97 with Nauman Ali, who made 45, before George Linde - bowling with strapping on a lacerated finger - claimed a five-for by dismissing Shaheen Shah Afridi, Pakistan all out for 298.
South Africa lost opener Dean Elgar for 17 at the hands of Shaheen in the ninth over of their response but, with the surface holding up well, Markram and Van der Dussen provided hope with an unbeaten stand of 94, the former hitting nine fours and a pair of sixes.
Yet with the highest chase in Rawalpindi coming in 2000 when Sri Lanka prevailed by reaching 220-8, history is against South Africa getting this especially difficult job done.