Pakistan were 157 for eight, with a lead of 169, at the lunch break.
Resuming on 100 for four, the visitors lost the wicket of captain Misbah-ul-Huq for 44. He attempted to reverse sweep Robin Peterson and, after only adding six runs to his overnight total, he looped the ball to Graeme Smith at short-fine leg.
Asad Shafiq (19) was unlucky when he played a defensive shot to Vernon Philander and the ball rebounded backwards on to his stumps.
The Proteas then took three wickets with three consecutive balls and left Pakistan's second innings in tatters.
Peterson took the first of them as Sarfraz Ahmed could only look on in disbelief after he left the delivery alone. He turned around and saw the ball, pitched outside leg, swing back on to the stumps, and he was on his way for five.
Overnight stalwart Azhar Ali went out to the first ball of Philander's next over, edging to a diving AB de Villiers for a well-played 65.
Off Philander's next delivery, Alviro Petersen reacted quickly to take a brilliant two-handed catch to his right and see off Umar Gul who faced just the one ball.
At lunch, Tanvir Ahmed was on one and Saeed Ajmal was on four not out. – Sapa