Pakistan, who were cruising at 92-1 in the 10th over while chasing a winning target of 145, lost five wickets for 23 runs in the 15th over, slipping to 115-6.The tour finale at SuperSport Park was tense as a result.
8th position Mohammad Nawaz guided the tourists to victory, scoring 25 runs off 21 balls, including two vital sixes in the final two overs.
Nawaz whipped a six over square leg off the fifth ball of the 19th over, then pulled another six over square leg off the fifth ball of the 20th over, as Pakistan required 16 from the last 12 balls.
When Pakistan needed two runs from the last two deliveries, this clinched the victory with a ball to spare.
In answer to South Africa's 144 all out in 19.3 overs, Pakistan finished on 149-7.
Fakhar Zaman, batting at No. 3, continued his red-shot form with a 60 off 34 balls to keep Pakistan on track.
Pakistan also won the one-day international series for a highly successful tour.
After being put in to bat, South Africa failed to save the T20 series, with only Rassie van der Dussen worrying Pakistan with his 52 from 36 balls. Just 36 runs were scored by South Africa's last eight batsmen.
Pakistan's outstanding bowling success set up the series victory, with Faheem Ashraf taking 3-17 and Hasan Ali taking 3-40.