South Africa were 64 for five at the interval on Friday.
Bowling his first spell in Test cricket in almost a year, Shoaib struck the first two crucial blows when he had AB de Villiers and Hashim Amla caught behind.
Leg-spinner Danish Kaneria followed up with the wickets of South African captain Graeme Smith and Herschelle Gibbs, while Mohammad Sami had Ashwell Prince caught at first slip.
Astonishingly, on a pitch which did not appear to have any demons, Pakistan put down three chances and still had their opponents in deep trouble.
In contrast to the first Test, which South Africa won by seven wickets, Pakistan fielded a potent four-man bowling attack, with Shoaib and Mohammad Sami replacing Shahid Nazir and Rana Naved-ul-Hasan.
De Villiers edged an attempted hook against Shoaib's 16th delivery of the match and the controversial fast bowler struck again when Amla gloved a catch down the leg side.
Kaneria came into the attack when Shoaib was rested after taking two for 17. Smith charged down the pitch and slammed the spinner's fourth ball past mid-off for four but was out for 28 off the next ball when he was deceived by a googly.
Wicketkeeper Kamran Akmal could not hold the chance but it bounced up for Younis Khan to catch it at slip.
Ashwell Prince was dropped by Akmal off Sami on two but was out four balls later, caught at first slip.
Kaneria had Jacques Kallis dropped at slip by Younis on 11 and Gibbs was dropped by Akmal off the next ball, only to miss a sweep off the following delivery to be leg before.
Kaneria had two for 12 off seven overs at lunch, while Kallis was unbeaten on 15.