Vernon Philander took two Pakistan wickets in a dramatic final session after South Africa capitulated to 262 all out on day one of the final Test of the series at the Wanderers.
The Proteas, eyeing a 3-0 whitewash, were 226-3 at tea but folded in spectacular fashion, losing seven wickets for just 33 runs in Johannesburg on Friday,
Aiden Markram, passed fit after recovering from a thigh injury, top scored with 90 and Theunis de Bruyn fell one short of a half-century before the tourists tore through the South Africa order.
The recalled Faheem Ashraf took 3-57, while Mohammad Amir, Mohammad Abbas and Hasan Ali claimed two wickets apiece as seven fell in just under 17.2 overs - the quicker bowlers thriving in the absence of Yasir Shah (knee).
Philander then shifted the momentum firmly in South Africa's favour by snaring Shan Masood caught behind and removing Azhar Ali in the same fashion from the next delivery, with Pakistan closing on 17-2.
Dean Elgar, captain with Faf du Plessis suspended due to a slow over-rate in the second Test, fell for only five after winning the toss when he was caught behind off Abbas but Markram and Hashim Amla prevented Pakistan from making further early inroads.
Markram played fluently, finding the gaps on both sides of the wicket and he was unbeaten on 78 at lunch after a glorious straight drive off Abbas (2-44) gave him a 14th boundary.
The opener missed out on a fifth Test century when he was strangled down the leg side off Ashraf to end a stand of 126 and Amla (41) followed after edging the recalled Shadab Khan to Asad Shafiq in the slips.
De Bruyn (49) and debutant Zubayr Hamza (41) put on 75 for the fourth wicket, but South Africa fell to pieces after the former was trapped leg before by Abbas.
Amir - who was this week recalled to the ODI squad - had Temba Bavuma and Hamza caught behind and Ashraf took two wickets in as many overs to wrap up the innings in a flash.
The procession of wickets continued when Pakistan started their reply, Masood given out caught behind following a review and Philander drawing an edge from Azhar to leave Pakistan in the mire on 6-2.
Imam-ul-Haq and nightwatchman Abbas were still there at stumps, but Pakistan will need to apply themselves on Saturday as they attempt to secure a consolation victory.