The result means the series is levelled 2-2, with the decider scheduled to be played in Cape Town on Wednesday.
Fielding first, Pakistan bowlers ran through South Africa, bundling the hosts for 164. Pakistan chased down the target in 32nd over with eight wickets in hand. Opener Imam-ul-Haq top scored with 71.
Shoaib Malik, who led the side in the absence of Sarfraz, said at the after-match presentation that he only found out after they arrived at the ground that Sarfraz had been banned.
The ban had still not been announced by the ICC when Malik walked out for the toss.
Malik's astute handling of his bowlers and fielders was on the show, as the visitors kept the Proteas under pressure throughout with aggressive tactics.
"It is a great honour to represent your country, as a player or a captain," said Malik. "When the responsibility comes you should make sure to give it your best shot."
Teenager Shaheen Shah Afridi made two early strikes, trapping Quinton de Kock in-front for nought before removing Reeza Hendricks (2), who was caught down the leg-side by stand-in wicketkeeper Mohammad Rizwan. Hashim Amla (59) and captain Faf du Plessis (57) then made half-centuries and put on a 101-run stand for the third wicket.
Spinners Imad Wasim and Shadab Khan kept the scoring rate in check and both Amla and du Plessis fell to the slow bowlers before the fast bowlers returned.
Mohammad Amir dismissed David Miller, the left-armer's first wicket in six ODIs, before Usman Shinwari claimed four wickets in six balls to rip apart the South Africa lower-order. His figures of four for 35 earned him the man of the match award.
Shinwari had Rassie van der Dussen caught behind for 18 and bowled Dale Steyn for a second-ball duck. Kagiso Rabada was caught behind first ball and Beuran Hendricks survived an appeal for lbw with what Shinwari hoped was the hat-trick ball.
The ball was crashing into the stumps but Shinwari acknowledged that the umpire had made the right call because there was a faint inside edge.
Du Plessis praised the Pakistan bowlers but said it was not a typical Wanderers pitch. "The ball spun quite a lot and was sticking in the surface," he said. "But you have to adapt. They have fantastic bowlers and they are putting pressure on us."
Malik deflected praise for the way the Pakistan players had shown energy and commitment in the field. "Not just today, in the previous games as well," he said. "You need a bit of luck to get across the line. We are all professionals and today our bowling attack did the job and they took wickets."
Imam, the top scorer in the series, looked in control from the start of Pakistan’s reply. He and Fakhar Zaman (44) put on 70 for the first wicket before he was joined by the in-form Babar Azam, who finished with 41 not out.
It was South Africa’s first defeat in eight matches on what has become known as ‘Pink Day’ with their players and many spectators dressed in pink in aid of breast cancer awareness. The victory is also the first-ever win for Pakistan at the Wanderers against South Africa. They had previously defeated the West Indies but never the Proteas at the venue.