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.
Pakistan 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.
Brief scores
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.