Wicketkeeper-batsman Mohammad Rizwan smashed a maiden century as Pakistan set a daunting 370-run target for South Africa on the fourth day of the second Test in Rawalpindi on Sunday.
At tea, South Africa were 37-1 with opener Aiden Markram batting on 14 and Rassie van der Dussen on four, as the tourists still need 333 runs in the remaining four sessions.
Dean Elgar was the man out, caught behind off fast bowler Shaheen Shah Afridi for 17.
Rizwan's masterclass helped Pakistan add 169 runs for the loss of four wickets in the day before being bowled out for 298.
Rizwan was at his best, putting on a match-turning 97-run partnership for the ninth wicket with number ten batsman Nauman Ali who made 45, frustrating South Africans who were looking for a series-levelling win.
Pakistan leads the two-match series 1-0 after winning the first Test by seven wickets in Karachi.
Rizwan, dropped on four by van der Dussen off Keshav Maharaj on Friday, punished South Africa and quashed their hopes of a win with 115 not out, spread over 292 minutes and laced with 15 boundaries.
He took a sharp single to reach his hundred, surpassing his previous best of 95 scored against Australia at Brisbane in November 2019.
The 97-run stand is also a new record for the ninth wicket against South Africa, bettering the 80 runs scored between Azhar Mahmood and Shoaib Akhtar at Durban in 1998.
Spinner George Linde, who took 5-64, recorded his first five-wicket haul when he dismissed the last man Shaheen for four. Maharaj finished with 3-118 while Kagiso Rabada had figures of 2-34.
Pakistan, resuming on 129-6, added 88 runs for the loss of Hasan Ali (five) and Yasir Shah (23) in the first session.
Hasan was the first to go when he was trapped leg-before in the sixth over of the day but Yasir helped Rizwan put on 53 for the eighth wicket in a stubborn stand.
Linde, who dropped Yasir off his own bowling when the batsman was on 15, finally had him caught behind by wicketkeeper Quinton de Kock to break the stand.