Pakistan completed a clean sweep of four trophies in four series against South Africa but had anxious moments before scrambling to a three-wicket win with one ball to spare in the fourth and final Twenty20 international at SuperSport Park in Centurion on Friday.
"It is a big moment for Pakistan. It is not easy winning matches in South Africa," captain Babar Azam said through an interpreter at the post-match presentation.
Pakistan, who earlier in the season defeated South Africa in Tests and T20 internationals in Pakistan, followed up a 2-1 one-day series win with a 3-1 victory in the T20s to round off a successful tour.
Medium-pace bowler Faheem Ashraf set up what seemed likely to be an easy win for Pakistan when he took three for 17 as South Africa were bowled out for 144 on what is usually a high-scoring ground.
Pakistan were cruising at 92 for one in the tenth over as Babar and Fakhar Zaman shared a impressive second-wicket partnership after Mohammad Rizwan was stumped in the first over.
But Fakhar, who hit five fours and four sixes in a 34-ball 60, went for one big hit too many and sliced a high catch to backward point.
Babar, who was named man of the series, was caught at wide third man for 24 three balls later and Pakistan found themselves in a collapse in which six wickets fell for 37 runs.
Two no-balls in the penultimate over by Sisanda Magala proved disastrous for the hosts, with the second resultant free hit being slammed for six by Mohammad Nawaz.
However, it still went down to the fifth ball of the over before Nawaz clinched victory with another six, off Lizaad Williams.
South Africa, with five key players released to the Indian Premier League and without appointed captain Temba Bavuma because of injury, batted poorly but clawed their way back into the game despite bowling four no-balls and seven wides.
"I am disappointed but we have young cricketers with great talent and I am proud of them," said stand-in captain Heinrich Klaasen.
"We showed we can fight and compete as a young group but we need to get more consistency in our performances."
Faheem earlier started a South African collapse similar to that which later afflicted Pakistan.
South Africa had reached 73 for one after the early loss of Aiden Markram when Faheem had Janneman Malan caught at mid-off for 33 in the ninth over.
He followed up with the wickets of Klaasen and George Linde. He bowled his four overs in succession and did not concede a boundary.
"My brief was clear from the captain but the tone was set by the new ball bowlers," he said.
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.
The series completed a truncated home season for South Africa, who lost a T20 series against England and gained their only series win when they won two Tests against Sri Lanka before taking on Pakistan.
Babar praised the facilities provided for his team in a bio-secure country club between Johannesburg and Centurion, with the matches shared between the two venues.
His team will now head to Harare for three T20 internationals and two Tests against Zimbabwe.