Fawad Alam's 109, his third Test ton, drove Pakistan's recovery-cum-resistance as the hosts fought back from their dire overnight position of 33/4 to sleep much easier on 308/8 at the end of day two of the first Test against South Africa in Karachi.
Pakistan, who bowled South Africa out for 220 on the first day, now have a lead of 88 runs on a pitch that didn't deteriorate markedly, but still took a fair bit of turn.
The pitch's changing condition wasn't much of an issue for the 35-year-old Karachi southpaw with an idiosyncratic batting stance, who soaked up the pressure for the better part of the day before transferring it to the South Africans in the final session.
Alam, who averages 70 in Karachi, brought up his third Test century off 220 balls with his second six while also hitting eight fours
Alam also made the most of a life on 35 when Dean Elgar missed a tough chance off Keshav Maharaj (2/71), but was quietly remorseless thereafter.
When he was eventually removed by Lungi Ngidi (2/55), who coaxed a false shot from the left-hander that was caught by Temba Bavuma at short midwicket, his 100 spanned 245 balls and nearly six hours.
It stood as a lesson for South Africa's batting profligacy and how they need to be better in the second innings to drag the game away from the hosts.
Alam was the lynchpin of three critical 50-plus partnerships that rescued Pakistan from a perilous 27/4 on the first evening.
Resuming the day on 33/4, Pakistan didn't lose a wicket in the morning session when Alam's alliance with Azhar Ali (51) took Pakistan to the safety off 104/4 at lunch.
Ali was slower, but resolute and raised his 33rd Test 50 off 146 balls.
He lasted only five more deliveries when Keshav Maharaj and Quinton de Kock combined to get rid of him and end the threatening 94-run stand.
The 55-run sixth wicket stand between Alam and Mohammad Rizwan (33) started to sap the energy from the visitors, who bowled diligently but without reward.
It was Ngidi who got rid of the dangerous Rizwan, who's edge was snared at slip by Faf du Plessis, but that only brought the effervescent Faheem Ashraf (64) to the crease.
The left-handers added a punchy 102 runs in just over 25 overs that moved Pakistan from a deficit of 44 to a lead of 58.
Ashraf should have been Kagiso Rabada's 200th Test scalp on 21, but captain and wicketkeeper Quinton de Kock shelled the opportunity. De Kock had a difficult day while also burning through his three reviews.
Ashraf, who was unluckily bowled by Anrich Nortje (2/84) late in the day, proceeded to a rapid third Test 50 off only 69 balls with seven fours, while the 50 and 100-partnership landmarks came off 84 and 148 balls respectively.
South Africa's day of misfortune was summed up Maharaj's dismissal of Hassan Ali, only to be flagged for a no-ball.