Pakistan overcame David Miller's 45-ball 85 to beat South Africa by four wickets in the third and final Twenty20 and clinch the series 2-1.
The 32-year-old legspinner Zahid Mahmood picked up 3-40 on debut and had reduced South Africa to 7-65 before Miller's clean hitting, with five fours and seven sixes in his unbeaten knock, powered South Africa to 8-164.
South Africa's Tabraiz Shamsi grabbed 4-25 in a game dominated by spinners, but Pakistan's lower order hung in to reach their target on 6-169 with eight balls to spare and record their 100th win in a T20 international.
Hasan Ali (20 not out) raised the victory with two sixes and a four off Andile Phehlukwayo as seamers again found it difficult to grip the wet ball because of dew.
"Credit must be given to David Miller for playing an outstanding innings and making the match interesting," Pakistan captain Babar Azam said.
"We told the players to play fearless cricket and that's why we finished on the right side."
Babar himself top-scored for his side with 44 off 30 balls.
Pakistan also beat South Africa 2-0 in the Test series before completing the double by handing the Proteas their first defeat in a T20 series in Asia.
Earlier, Babar had won the all-important toss in the winner-takes-all game and his ploy of adding an extra spinner paid dividends.
South Africa ran into early trouble in the batting powerplay when leftarm spinner Mohammad Nawaz removed in-form Reeza Hendricks and Jon-Jon Smuts in his first two overs before South Africa limped to 3-41 in six overs.
Mahmood baffled the Proteas as captain Heinrich Klaasen top- edged a sweep for a duck and Janneman Malan (27) was trapped lbw off the back foot.
But Miller cut loose in the last four overs, and smashed four sixes off the last one from seamer Faheem Ashraf which went for 25.
Player of the series, wicketkeeper-batsman Mohammad Rizwan (42), and Haider Ali (15) provided Pakistan with a brisk start of 51 off 37 balls.
Babar, who scored 0 and 5 in the previous two matches, demoted himself to number three and held the innings together before Shami returned and claimed the wickets of Hussain Talat and Asif Ali.
In between Shami's strike, Babar was clean bowled by Dwaine Pretorius which left Pakistan struggling at 5-117 in the 15th over.
However, Nawaz (18 not out) and Hasan got the home team over the line in the 19th over.