South Africa 247 for 5 (Van der Dussen 76*, de Kock 41, Nabi 2-35) beat Afghanistan 244 (Azmatullah 97*, Coetzee 4-44, Maharaj 2-25) by five wickets
Ahmedabad: Rassie van der Dussen hit an unbeaten 76 to take South Africa to a nervy five-wicket win over Afghanistan in their final World Cup group game.
Gerald Coetzee took 4-44 as the Proteas bowled Afghanistan out for 244 after Azmatullah Omarzai made an unbeaten 97 to rescue the innings from 116-6.
South Africa made hard work of the chase but held their nerve to get over the line in the 48th over.
Defeat officially ended Afghanistan's chances of making the top four.
Jonathan Trott's side needed to win a highly improbable 438 runs to overhaul New Zealand on net run rate and stay in contention to reach the knockout stages but, after opting to bat first, lost wickets in clusters.
After a steady start, they lost three wickets for four runs to slip from 41-0 to 45-3 and then another mini collapse saw them lose three wickets in four overs midway through the innings.
However, Azmatullah held Afghanistan together with a well-paced knock, biding his time before accelerating late on, but three dot balls to end the innings left him three shy of a maiden international century.
In reply, South Africa, who have dominated sides when batting first but struggled chasing, started well with openers Quinton de Kock and Temba Bavuma putting on 61.
They fell in quick succession but Van der Dussen and Aiden Markram continued the momentum with a 60-run stand.
However, every time the Proteas appeared to be cruising, Afghanistan took a wicket to drag them back and when David Miller was dismissed with 62 still needed, the game was in the balance.
Van der Dussen and Andile Phehlukwayo remained composed, though, and having whittled down the runs required, they finished it in a hurry with the latter going six, four, six to seal the win.
With a number of players struggling with slight injuries throughout the game, South Africa now have a few days to rest and recover before their semi-final against Australia.