Pakistan claimed their first bilateral one-day international series victory over South Africa after a narrow one-run win in Port Elizabeth on Wednesday.
The tourists now lead the three-match series 2-0 after staging a late fightback in a contest which was reduced to 45 overs each due to rain.
Ahmed Shehzad hit a century as Pakistan were bowled out for 262, with South Africa seamer Dale Steyn returning ODI best figures of 6-39.
The Proteas seemed on course to chase down the target after a fourth-wicket stand of 110 from Hashim Amla and AB de Villiers, but some fine death bowling from Junaid Khan and Saeed Ajmal sealed the win for Pakistan.
Both De Villiers (74) and Amla (98) fell going for big shots in the closing overs, and suddenly South Africa found themselves needing nine off Junaid's final over.
To add further drama to the situation, Junaid had been struck on the shin by a powerfully-hit Amla shot in his previous over that led to him leaving the field for treatment.
However, the paceman (3-42) returned and dismissed JP Duminy (15) with his second ball and, with eight needed off four, David Miller (2 not out) and Ryan McLaren (0no) could not get South Africa over the winning line.
Earlier, Pakistan opener Shehzad and South Africa fast bowler Steyn both produced outstanding individuals displays.
The 22-year-old Shehzad struck 102 off 112 balls - his third century for his country - to provide the bulk of Pakistan's runs, with the next-best contributions coming from Sohaib Maqsood and Umar Akmal, who both made 42.
Steyn, meanwhile, was devastating with the ball, taking all but two of the Pakistan wickets to fall to bowlers - the other two dismissals being the run-out of Shehzad and that of Anwar Ali (7), who was out obstructing the field.
Despite Steyn's efforts, Pakistan's total looked a tough one for South Africa, especially as they were bowled out for 195 chasing 219 in the first contest in Cape Town.
But Amla, De Villiers and Quinton de Kock (47) looked to have put the Proteas on the verge of levelling the series with some superb batting.
De Villiers was brutal in his knock, hitting his runs off just 45 balls with eight fours and two sixes, while Amla took a more sedate approach, facing 131 deliveries, but the homes side ultimately fell short on on 261-6.