Pakistan almost threw away the chance of a series victory before Mohammad Nawaz clattered a pair of late sixes to edge out South Africa.
Pakistan captain Babar Azam put South Africa to the sword with a stunning 122 as his team cruised to victory at Centurion.
George Linde made an impact with bat and ball while Aiden Markram scored another half-century as South Africa defeated Pakistan.
South Africa are missing a number of stars due to injury and IPL commitments, but they came close against Pakistan in an entertaining T20I.
Temba Bavuma will be missing for South Africa, but Pakistan have the in-form Fakhar Zaman available for the Twenty20 fixtures.
Pakistan beat a weakened South Africa side in the third ODI to ensure they emerged triumphant from the three-match series.
Fakhar Zaman delivered the highest score in a chase in ODI history, but it was not enough to help Pakistan to victory over South Africa.
Temba Bavuma suffered defeat in his first game as South Africa's limited-overs captain after a thrilling battle with Pakistan at Centurion.
A new reign begins for South Africa on Friday when Temba Bavuma takes charge in the first of three ODI games against Pakistan.
Rugby SA are in full support for the British and Irish Lions to tour South Africa in July and August, despite coronavirus complications.