South Africa reinforced their status as the world's number one Test team when they beat Pakistan by four wickets on the fourth day of the second Test at Newlands on Sunday.
The victory, with a day to spare, gave South Africa a winning 2-0 lead in the three-match series. It came after a dramatic Pakistan collapse in their second innings.
Pakistan were bowled out for 169 after starting the day on a relatively comfortable 100 for three. They lost their last six wickets for 22 runs on either side of lunch. At one stage four wickets fell in 13 balls, including three off successive deliveries.
The collapse was engineered by left-arm spinner Robin Peterson and opening bowler Vernon Philander, who took three wickets each before Dale Steyn finished off the Pakistan innings.
Peterson finished with three for 73 and Philander took four for 40.
The result was a disappointment for Pakistan, who had seemed on top after two days before a strong fightback by South Africa's lower order batsmen on Saturday.
Pakistan off-spinner Saeed Ajmal took four for 51 in South Africa's run chase to finish with match figures of ten for 147.
Set to make 182 to win, South Africa lost Alviro Petersen ten runs into their chase, when he was leg before wicket to Umar Gul for one.
Captain Graeme Smith and Hashim Amla put on 53 for the second wicket before Smith was leg before to Saeed Ajmal for 29 shortly before tea.
Ajmal gained a second leg before decision when he dismissed Jacques Kallis for 21.
Amla and AB de Villiers shared a rapid 62-run partnership for the fourth wicket before both batsmen perished playing attacking shots. Faf du Plessis became Ajmal's tenth victim of the match before Dean Elgar hit the winning run.
Pakistan made slow but solid progress at the start of the day, seeing off the threat of fast bowlers Philander and Steyn.
But they had only added 14 runs in 8.2 overs to their overnight total of 100 for three when captain Misbahul Haq top-edged a sweep against Peterson and was caught by Smith at short fine leg for 44.
Azhar Ali and Asad Shafiq added 33 for the fifth wicket before Shafiq was unlucky to see a defensive stroke against Philander bounce up and then back on to his stumps. The wicket fell five overs after the umpires called for a replacement ball after the original ball went out of shape.
Peterson bowled Sarfraz Ahmed, who padded up to a ball pitched outside leg stump, with the last ball of the next over. Philander then took wickets with the first two balls of the following over.
A long vigil by Azhar ended when he edged an outswinger to wicketkeeper de Villiers. Azhar made 65 off 193 balls with seven fours. Gul edged the next ball and Petersen flung himself to his left at third slip to take a spectacular catch.
South Africa were without fast bowler Morne Morkel, who left the field with a hamstring injury on Saturday, but Peterson bowled accurately for all but two overs from the Kelvin Grove end, enabling Smith to use Philander and Steyn in short bursts.
Philander, who took five for 59 in the first innings, had match figures of nine for 99.
PAKISTAN: First innings 338
SOUTH AFRICA: First innings 326
PAKISTAN: Second innings (overnight 100-3)
Hafeez lbw b Steyn 0
Jamshed lbw b Philander 0
Azhar c De Villiers b Philander 65
Younis b Steyn 14
Misbah c Smith b Peterson 44
Shafiq b Philander 19
Sarfraz b Peterson 5
Tanvir not out 10
Gul c Petersen b Philander 0
Ajmal b Peterson 4
Irfan c Petersen b Steyn 2
Extras: (lb-2, w-4) 6
Total: (All out in 75.3 overs) 169
Fall of wickets: 1-0, 2-7, 3-45, 4-114, 5-147, 6-152, 7-152, 8-152, 9-158.
Bowler O M R W
Steyn 18.3 5 38 3
Philander 19 6 40 4
Morkel 3.1 0 8 0
Peterson 29 8 73 3
Kallis 5.5 2 8 0
SOUTH AFRICA: Second innings
Petersen lbw b Gul 1
Smith lbw b Ajmal 29
Amla b Ajmal 58
Kallis lbw b Ajmal 21
De Villiers c Sarfraz b Tanvir 36
Du Plessis lbw b Ajmal 15
Elgar not out 11
Peterson not out 1
Extras: (b-5, nb-5) 10
Total: (For 6 wkts in 43.1 overs) 182
Fall of wickets: 1-10, 2-63, 3-88, 4-150, 5-168, 6-180.
Bowler O M R W
Irfan 10 1 35 0
Gul 8 0 46 1
Ajmal 18.1 2 51 4
Hafeez 2 1 11 0
Tanvir 5 0 34 1
Result: South Africa won by four wickets and lead the three-match series 2-0.
Player-of-the-match: Robin Peterson.