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.
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.
Earlier, Temba Bavuma and Quinton de Kock steered South Africa to a first-innings lead.
Bavuma made 53 and De Kock hit 45 before South Africa were bowled out for 223.
Bavuma moved to an assured half-century off 66 balls but was then tied down by some accurate bowling before edging Afridi to wicketkeeper and captain Sarfraz Ahmed for 53 off 87 balls with nine fours.
De Kock made his runs off 53 balls with five fours before he was last man out, driving Amir to cover.