Bavuma’s hamstring troubled him throughout the match while fielding and batting in a worrying sign ahead of their semi-final.
De Kock, who will quit one-day internationals when this World Cup is over, overtook New Zealand’s Rachin Ravindra (565) to reclaim his top spot in the tournament batting chart with 591 runs including four centuries.
The Proteas put their chase back on track in a third-wicket stand of 50 but leg-spinner Rashid Khan broke through with the wicket of Aiden Markram for 25.
South Africa looked in trouble when Rashid bowled Heinrich Klaasen for 10 but Van der Dussen stood firm to build partnerships including an unbeaten 65-run stand with Andile Phehlukwayo, who hit the winning six in an unbeaten 39.
ICC World Cup 2023: New Zealand beat Sri Lanka, are almost through to the semifinals
Earlier Afghanistan slipped to 116-6 before Azmatullah hit his ODI best to lift the team to a competitive total.
South Africa fast bowler Gerald Coetzee took four wickets while spinner Keshav Maharaj returned impressive figures of 2-25.
De Kock played a key part with his six wicketkeeping dismissals to equal a World Cup record of Australia’s Adam Gilchrist (v Namibia – Potchefstroom, 2003) and Pakistan’s Sarfaraz Ahmed (v South Africa – Auckland, 2015).
Openers Rahmanullah Gurbaz and Ibrahim Zadran started aggressively before Maharaj struck with his first ball to have Gurbaz caught for 25.
Coetzee sent back Ibrahim in the next over to check the batting surge and Afghanistan slipped from 41-0 to 45-3 when Maharaj had skipper Hashmatullah Shahidi caught behind for two.
ICC World Cup 2023: Maxwell’s double ton takes Australia to World Cup semifinals against Afghanistan
Afghanistan lost three more wickets to be in danger of getting bowled out in less than their quota of 50 overs but Azmatullah stood firm to play out the innings.
Afghanistan, led by Hashmatullah Shahidi, ended a strong campaign after they beat defending champions England, Pakistan, Sri Lanka and the Netherlands.
(With inputs from AFP)