Afghanistan now have an unassailable 2-0 lead in their ODI series, with South Africa unable to mount any sort of threat in the sweltering heat in Sharjah.
Gurbaz set the tone from the off with his stand of 105 from 110 balls, which included 10 fours and three sixes, and put together a 101-run partnership with Rahmat Shah (50).
Nandre Burger eventually took Gurbaz, but Azmatullah Omarzai kept the pressure on with his unbeaten 86, bringing up his fastest ODI fifty, as they finished on 311-4.
With the intimidating target set, South Africa's chase got off to a decent start through Temba Bavuma (38) and Tony de Zorzi (31), but Afghanistan's bowlers soon stepped up their game.
Rashid Khan (5-19) and Nangeyalia Kharote (4-26) gave their opponents little to work with as none of the final seven batters hit double figures, with South Africa slumping to 134 all out in the 35th over.
Data Debrief: A historic stand
Gurbaz's century was his seventh in ODIs, breaking Mohammad Shahzad's record, while Shah brought up his 29th half-century in their brilliant stand.
Afghanistan's 177-run win against SA is their largest margin of victory in terms of runs in ODIs, beating their 154-win against Zimbabwe. It was also the tenth time they topped 300 in ODI cricket, and the first against South Africa.