South Africa reached 37 without loss at lunch in their second innings after Pakistan's tail had extended their lead to 158 on the third day of the first Test in Karachi on Thursday.
SCORECARD | Pakistan v Proteas, 1st Test
Dean Elgar was 18 not out and Aiden Markram on 16 as South Africa, playing their first Test in Pakistan for 14 years, still trailed by 121.
Pakistan's lower order resumed the morning on 308-8 and frustrated South Africa by plundering 70 runs before being finally bowled out for 378.
South Africa's pace spearhead Kagiso Rabada bowled Hasan Ali for 21 to reach 200 wickets in his 44th Test, raising his hands to heaven in gratitude.
Rabada, 25, is the eighth South African to take 200 or more Test wickets.
Pakistan were at that point 323-9 but Yasir Shah and Nauman Ali added 55 valuable runs for the final wicket.
Yasir, who has a Test century to his name, in Australia in 2019, hit a six and four fours in his 38 not out while debutant Nauman scored three boundaries before falling for 24.
Rabada with 3-70 and spinner Keshav Maharaj, who took 3-90, were the pick of the South African bowlers.
South Africa's batsmen are now faced with the task, on a wearing pitch, of resisting spin duo Nauman and Yasir who shared five wickets as the visitors were bowled out for 220 in their first innings.