A magnificent spell of fast bowling from Duanne Olivier inspired a Pakistan collapse after tea on the second day of the first Test against South Africa at SuperSport Park on Thursday, leaving South Africa needing 149 to win.
Pakistan slipped from 100 for one at tea to 190 all out, at one point losing five wickets for 25 in 11 overs.
The last wicket fell shortly before the close of play which did not leave enough time for South Africa to start their chase.
Olivier took two wickets in four balls immediately after the tea interval and went on take five for 59 for match figures of 11 for 96 following his six for 37 in the first innings.
Imam-ul-Haq (57) and Shan Masood (65) gave Pakistan hope of setting a difficult target for the hosts on a pitch which has helped the fast bowlers throughout.
But Imam was bowled off an inside edge in the first over after tea and Masood quickly found himself effectively fighting a lone battle before he was ninth out after a fighting 120-ball innings which included seven fours.
Kagiso Rabada and Dale Steyn supported Olivier with three and two wickets respectively.
It was the second successive day on which 15 wickets fell. Although the pitch appeared to be playing slightly easier than on the first day, Pakistan will seek to make early inroads on Friday after restricting South Africa to 223 all out in the first innings.
Mohammad Amir took four for 62 and teenager Shaheen Shah Afridi claimed four for 64 and together with Hasan Ali (two for 70) are likely to make South Africa work hard to take a 1-0 lead in the three-match series.
Temba Bavuma (53) and Quinton de Kock (45) were mainly responsible for South Africa squeezing out a 42-run first-innings lead.
Imam and Fakhar Zaman wiped out the deficit with a first-wicket stand of 44 and Masood joined Imam in a 57-run second-wicket partnership.
After a shaky start, the left-handed Imam hurried to 15 off 11 balls but all three of his boundaries to that point were off the edge of his bat.
He was still on 15 when he was dropped low down by Hashim Amla at first slip off Dale Steyn. But he then batted solidly in reaching fifty off 71 balls with seven fours and a hooked six off Olivier.
After bowling Imam, Olivier claimed the wicket of the experienced Azhar Ali, with the help of a diving Rabada at midwicket after a mistimed pull shot.
The rest of the batting crumbled, with Steyn having Asad Shafiq caught behind and Rabada ripping out the next three batsmen cheaply.