South Africa 106 for 4 ( Markram 32, Hasan Ali 2-29) trail Pakistan 272 (Ashraf 78*, Azam 77, Nortje 5-56, Maharaj 3-90) by 166 runs
Rawalpindi: Pakistan took four early South African wickets to dominate the second Test in Rawalpindi on Friday, despite a five-wicket haul by touring fast bowler Anrich Nortje.
South Africa were in trouble at 106-4 after the second day's play on a tricky Rawalpindi stadium pitch, trailing Pakistan's first innings total of 272 by 166 runs.
At close, South African skipper Quinton de Kock was on a breezy 24 with five boundaries and Temba Bavuma -- surviving two close appeals -- was unbeaten on 15 after Pakistan's medium pacer Hasan Ali took two wickets off two balls.
Hasan had opener Dean Elgar caught behind for 15 with the fifth delivery of his third over, and at the next ball bowled Rassie van der Dussen for a duck in the last over before tea.
Senior batsman and former skipper Faf du Plessis, who failed in the first Test in Karachi with scores of 23 and ten, managed 17 before he was caught behind off pacer Faheem Ashraf, playing a loose shot.
Four over before close opener Aiden Markram's fighting 60-ball 32 ended when he top edged spinner Nauman Ali to Shaheen Shah Afrid at mid-wicket, leaving South Africa tottering at 81-4.
Earlier, Nortje grabbed his third five wicket haul with 5-56 to restrict Pakistan's total.
The 27-year-old took the prized wicket of Babar Azam off the second ball of the day before wrapping Pakistan's innings half an hour before tea.
Nortje bowled with fire and aggression on a flat, brownish pitch which was suited more to spin.
Keshav Maharaj finished with 3-90.
Despite South Africa's controlled bowling, allrounder Ashraf played a knock of 78 not out studded with 12 hits to the boundary -- his fourth Test half century.
Pakistan had looked to Azam and Fawad Alam to build on their partnership of 123 after rain cut short the first day to 58 overs.
Azam slashed at a short delivery from Nortje and was smartly snapped head high by du Plessis in the second slip for his overnight score of 77.
Azam's dismissal was the start of a mini-collapse which saw Pakistan lose two wickets in the space of 34 balls with the addition of just four runs after resuming at 145-3.
The other overnight batsman Alam was run out after he tried to steal a quick single with a push to cover but failed to beat a direct throw from Bavuma at the non-striker's end.
Alam could only add three to his overnight score of 42.
Azam, who was looking set for his sixth Test century, had hit 12 boundaries off 127 balls.
Ashraf then added 41 with Rizwan but once South Africa took the second new ball Nortje struck again, having Rizwan caught off a miscued hook for 18.
Pakistan lead the two-match series 1-0.