With the series tied at one win apiece coming into the third game of the five-match series, South Africa set Pakistan an enormous challenge making 5-343 from 50 overs on the back of a record-breaking 238-run partnership between Hashim Amla and AB de Villiers.
Amla made 122 and de Villiers 128 as South Africa posted the huge score and Pakistan didn’t look to be any hope at 5-132 but that's when Afridi strode to the wicket. He smashed four boundaries and seven sixes, including one which went onto the roof at Wanderers Stadium and out of the ground.
However, when he was eventually out for 88 from 48 balls, it all but ended Pakistan's charge and they were bowled out for 309 in 48.1 overs to fall 35-run shorts of their chase to hand the Proteas a 2-1 series lead ahead of Game 4 in Durban on Thursday.
Pakistan could very well have lost the match at the toss which captain Misbah-ul-Haq won but sent South Africa in to bat first.
The visitors did start well getting rid of Graeme Smith for three when he was bowled by the 7'1 Mohammad Irfan.
Pakistan then had South Africa 2-42 from 14 overs to be well on top with Colin Ingram out for 17 when he was caught behind by Kamran Akmal also off Irfan.
However, that brought together de Villiers and Amla for an incredible third-wicket partnership that ended up seeing the pair both reach centuries and combine for 238 runs in just 182 balls.
The Proteas went from being in trouble two wickets down and only scoring at three runs an over, to now be 3-280 by the time Amla was out in the 45th over.
Amla made 122 from 113 balls with nine boundaries and a six as he recorded his 11th one-day international century.
De Villiers survived two more overs before falling for 128 from 108 balls with 12 fours and three sixes in what was his 14th ODI century.
Faf du Plessis then made a rapid-fire 45 from 19 balls with four boundaries and three sixes to help South Africa to an eventual 5-343.
It was a tough outing for Pakistan's bowlers but Irfan survived unscathed taking 2-34 from seven overs.
Fellow left-arm opening bowler Junaid Khan did well with 0-42 from 10 overs but Wahab Riaz finished with 2-93 from 10 overs, Afridi 0-55 from seven, Mohammad Hafeez 0-49 from six and Saeed Ajmal 1-62 from 10.
Pakistan had a mountain of a task needing 344 runs to win and lost wickets consistently on their way to being 5-132 with Nasir Jamshed gone for 10, Akmal for 30, Hafeez for 57, Younis Khan for 19 and Shoaib Malik for four.
The tourists weren’t ready to throw in the towel just yet, though, and captain Misbah and Afridi put on a 71-run stand for the sixth wicket before the skipper fell for 28.
It was Afridi doing all the damage as he hit the South African bowlers all round the Wanderers.
His seven sixes including one off Ryan McLaren that went over long on and simply had to be seen to be believed as it disappeared out of the ground.
McLaren did think he had him out bowled, though, with Afridi on 73 and the pair had an angry exchange as the Pakistan excitement machine departed. However, umpire Billy Bowden went upstairs and McLaren had bowled a front-foot no ball.
He then bowled a wide at Afridi meaning he had a second free hit because of the no ball and then on that next delivery Afridi hit the unbelievably long six.
Afridi went on to make 88 and looked capable of hitting Pakistan to victory but he eventually holed out to McLaren at long-off from the bowling of Lonwabo Tsotsobe.
Pakistan was then 7-244 and despite 45 from Riaz, eight from Ajmal and nine from Junaid, they never looked likely to get close to their target and were bowled out for 309.
Tsotsobe took 3-74 from 10 overs for South Africa with McLaren taking 3-56 from nine, Robin Peterson 2-51 from 10, Dale Steyn 1-48 from 10 and Rory Kleinveldt 1-77 from 9.1.