Rahmanullah Gurbaz nearly scripted history with three consecutive sixes in the decisive moments, but Keshav Maharaj dismissed him off the final ball to seal the thrilling win after more than four hours of high drama.
The match had ended in a tie after both teams posted 187 in their allotted 20 overs.
South Africa were powered by Ryan Rickelton’s explosive 61 off 28 balls and Quinton de Kock’s 59.
In reply, Afghanistan rode on Gurbaz’s blistering 84 off 42 balls and looked set to register their first win of the campaign.
However, despite Kagiso Rabada’s twin no-balls that handed them crucial lifelines, Afghanistan failed to capitalise and fell just short in the Super Over contest.
With the win, South Africa moved to second place in Group D with four points, level with table-toppers New Zealand.