Pakistan grabbed three late wickets by its spinners and left South Africa in trouble at 187-4 in its second innings at stumps on day three of the first test on Thursday.
Aiden Markram and Rassie van der Dussen led South Africa's resistance in overturning a 158-run first-innings deficit. Their half-centuries in a gritty 127-run stand nosed the Proteas ahead after tea, but both batsmen were dismissed within the day's last 33 balls, along with Faf du Plessis for 10.
South Africa was effectively 29-4 with two days to play. Legspinner Yasir Shah bagged 3-53 and Nauman Ali 1-27.
Aiden Markram made 74 and Van der Dussen 64, digging in together for nearly 3 1/2 hours. At stumps, captain Quinton de Kock was yet to score and nightwatchman Keshav Maharaj was 2 not out.
Shah ended the threatening stand by having Van der Dussen caught close to the wicket, and then had du Plessis plumb leg before wicket off a sharp googly. Du Plessis made a successful lbw video referral before he scored and was also dropped on 6.
Nauman secured Pakistan's advantage when he induced Markram forward to block and the ball nicked the bat's shoulder and gave Abid his second catch at silly point.
Earlier, Pakistan was bowled out for 378 in the morning, Shah leading the tailenders with an unbeaten 38 valuable runs.
South Africa scored only 47 runs in the middle session and lost only Dean Elgar, for 29 to Shah when wicketkeeper Mohammad Rizwan dived full length in front of the stumps and plucked a stunning two-handed catch.
Markram and Van der Dussen rode their luck.
Markram survived a video referral on 22 and was dropped four runs later by captain Babar Azam at 71-1. Van der Dussen was adjudged lbw by umpire Aleem Dar off seamer Faheem Ashraf soon after reaching his half-century but the South African got the decision overruled.
Van der Dussen overhauled the deficit in the same over when he guided Ashraf through gully to third man for a boundary before falling to Shah.
Shah ended Pakistan's innings in the first hour with a flourish, making an unbeaten 38 off 37 balls and sharing a 55-run, last-wicket stand with Nauman, 24.
Pakistan recovered from 33-4 on day one to post a commendable total on the back of Fawad Alam’s patient century and contributions from the lower order.
Kagiso Rabada’s 200th test wicket was the highlight for South Africa after Pakistan resumed on day three at 308-8. Rabada reached the milestone in his first over of the day when he uprooted Hasan Ali’s middle stump as the batsman attempted a reckless pull on 21.
The fast bowler, playing his 44th test, became the youngest South African at 25 to complete 200 test wickets. He finished the innings with figures of 3-70.
Shah ensured Pakistan stretched its lead beyond 150 runs by smashing four boundaries and also lofting Maharaj (3-90) over long on for a six before the left-arm spinner ended the innings by having Nauman trapped lbw. Lungi Ngidi took 2-57 but fast bowler Andrich Nortje returned an expensive 2-105.