Duanne Olivier took his third five-for of the series to restrict the visitors to 185/10 before Pakistan's bowlers fought back on the second day of the third Test against South Africa at the Wanderers.
Olivier took five wickets for 51 as South Africa gained a first innings lead of 77.
But the hosts failed to take dominate, struggling to 135 for five at the close, an overall lead of 212.
South Africa were reduced to four for 45 at once stage after a double strike from Faheem Ashraf in his first over.
Hashim Amla made a patient 42* against disciplined bowling, while Quinton de Kock lifted the scoring rate late in the day with 34*.
Another Olivier five-for
Fast bowler Olivier was twice involved in crucial breakthroughs as Pakistan were bowled out for 185 in their first innings.
He ended an hour of frustration for South Africa when he took two wickets in four balls immediately after the morning drinks break, ending the stubborn resistance of nightwatchman Mohammad Abbas, who batted for 88 minutes and faced 51 balls in scoring 11.
Three balls later Asad Shafiq ducked a bouncer but was caught behind off his glove.
The first hour of play on day two witnessed a bizarre fielding show from the hosts as both Abbas and Imam-ul-Haq, who went on to make 43, were both dropped twice in the cordon. The Proteas also missed two run-out chances.
Pakistan were 91 for five when Imam was caught at second slip off Vernon Philander but Babar Azam (49) and captain Sarfraz Ahmed (50) put on 78 off only 61 balls for the sixth wicket.
Kagiso Rabada ended the partnership when Sarfraz was caught at first slip and four balls later Olivier had Azam caught at long leg. Olivier made it a double strike when Faheem Ashraf was out first ball, splicing a mistimed pull to short leg.
Stand-in captain Dean Elgar was caught behind for five off Mohammad Amir and while his opening partner and first innings top-scorer Aiden Markram followed after making a brisk 21.
The South African innings was in disarray when Ashraf dismissed both Theunis de Bruyn and new cap Zubayr Hamza in the space of two balls before Amla and Temba Bavuma (23) added 48 for the fifth wicket. It was left to De Kock to lift the tempo.