South Africa lost 7-33 as they were bowled out for 262 before reducing Pakistan to 17-2 at the end of day one of the third Test.
The Proteas appeared in a strong position at 229-3, with Theunis de Bruyn (49) and debutant Zubayr Hamza (41) stretching their fourth-wicket stand to 75 after Aiden Markram had made a swift 90 at the top of the order.
However, Mohammad Abbas trapped De Bruyn lbw to trigger a collapse that saw the final seven South African wickets fall in the space of 17.2 overs in Johannesburg.
Vernon Philander soon had Pakistan wobbling in their reply though, as he removed Shan Masood and Azhar Ali in successive balls before Imam-ul-Haq and night-watchman Abbas battled through to the close.
Stand-in Proteas skipper Dean Elgar won the toss and elected to bat first but that was as good as his morning got as he nicked Abbas behind for five in the second over.
Markram and Hashim Amla then added 126 for the second wicket and although both fell in the afternoon session - Faheem Ashraf having Markram strangled down the legside 10 short of his century and Amla well caught at slip off leg-spinner Shadab Khan - De Bruyn and Hamza ensured the hosts remained well placed at tea.
The game turned quickly after the interval, though, and the wickets were shared among the Pakistan seamers. Ashraf ended with 3-57, while there were two wickets apiece for Abbas (2-44), Mohammad Amir (2-36) and Hasan Ali (2-75).
The tourists' batsmen, under pressure from Philander and Dale Steyn, were unable to back up their bowlers' efforts in the nine overs before stumps and Imam and Abbas will hope to start the rebuild on day two as they target a consolation victory in the series.
Watch day two of the third Test between South Africa and Pakistan from 7.55am, Saturday on Sky Sports Cricket.