Pakistan were in trouble at 33 for four wickets in reply to South Africa's 220 at the close of play Tuesday on the opening day of their first Test in Karachi.
Azhar Ali and Fawad Alam were unbeaten on five each after South African pace bowler Kagiso Rabada rocked the top order with two wickets for just eight runs.
The visitors looked set earlier before Pakistan spinners Yasir Shah (3-54) and Nauman Ali (2-38) weaved their magic.
Opener Dean Elgar top scored with 58, while George Linde made 35.
The two-match series marks South Africa's first tour to Pakistan since 2007.