Pakistan beat South Africa by three wickets with one ball to spare in the fourth and final Twenty20 international at SuperSport Park in Centurion on Friday.
It clinched a 3-1 series win for the tourists.
Pakistan seemed to be cruising when they reached 92 for one in the 10th over after bowling out South Africa for 144 on what is usually a high-scoring ground.
But six wickets fell for 27 runs after Fakhar Zaman was out for a hard-hit 60 off 34 balls before Mohammad Nawaz sealed the win with a six off the penultimate ball.
Pakistan's 3-1 series win completed a clean sweep of four successful series against South Africa during the season.
They won a Test and T20 series in Pakistan and a one-day and T20 series in South Africa.
South Africa: 144 in 19.3 overs (H. van der Dussen 52, J. Malan 33; Faheem Ashraf 3-17)
Pakistan: 149-7 in 19.5 overs (Fakhar Zaman 60; S. Magala 2-33).
Result: Pakistan won by three wickets
Earlier, Pakistan medium-pace bowler Faheem Ashraf sparked a South African collapse.
Ashraf took three for 17 as South Africa, who were put into bat after losing the toss, were bowled out for 144.
South Africa had reached 73 for one after the early loss of Aiden Markram when Ashraf had Janneman Malan caught at mid-off for 33 in the ninth over.
Ashraf followed up with the wickets of South African captain Heinrich Klaasen and George Linde. He bowled his four overs in succession and did not concede a boundary.
Fast bowlers Hasan Ali and Haris Rauf took three for 40 and two for 18, respectively.
Rassie van der Dussen top-scored for South Africa with 52 off 36 balls.
Pakistan chased down a target of 204 with nine wickets and two overs to spare on the same ground two days earlier.
Captain Babar Azam, who scored 122 in that run chase, named an unchanged side while South Africa made two changes.
All-rounder Wiaan Mulder and left-arm spinner Bjorn Fortuin came into the side, replacing batsman Pite van Biljon and left-arm fast bowler Beuran Hendricks.
Earlier, Pakistan won the toss and decided to bowl first. South African captain Klaasen had said he would have preferred to bowl. “It looks a good wicket again,” he said.
South Africa: Heinrich Klaasen (captain, wkt), Aiden Markram, Janneman Malan, Rassie van der Dussen, George Linde, Andile Phehlukwayo, Wiaan Mulder, Sisanda Magala, Bjorn Fortuin, Lizaad Williams, Tabraiz Shamsi
Pakistan: Babar Azam (captain), Mohammad Rizwan (wkt), Fakhar Zaman, Mohammad Hafeez, Haider Ali, Asif Ali, Faheem Ashraf, Mohammad Nawaz, Hasan Ali, Shaheen Shah Afridi, Haris Rauf
Umpires: Shaun George, Adrian Holdstock (both RSA); Television umpire: Allahudien Paleker (RSA); Match referee: Andy Pycroft (ZIM)