Pakistan, chasing a stiff target of 187 for victory, were on track at 69 for two in the ninth over before they lost their next five wickets for just 19 runs at Trent Bridge.
As soon as South Africa captain Graeme Smith, who'd top scored with 70 in a total of 186 for seven, brought on his slow bowlers the match veered back in the Proteas' favour.
Ahmed Shahzad was bowled lbw to van der Merwe and the same bowler also held a sharp return catch to get rid of Pakistan captain Younus Khan. The innings then subsided long before Saeed Ajmal was last man out.
Ajmal and Afridi took four wickets between them to prevent South Africa posting a colossal total after Smith and Jacques Kallis put on 80 inside 10 overs for the first wicket.Left-handed opener Smith, who won the toss, faced 53 balls with one six and nine fours while Herschelle Gibbs weighed in with 42.
But Afridi saw off both Smith and Gibbs while Kallis was undone by Ajmal and it needed a 14-ball 32 from Albie Morkel, featuring three sixes, to bolster South Africa's total.
Meanwhile, New Zealand captain Daniel Vettori, rolled in the wickets as the Black Caps beat defending champions India at Lord's, had forecast on Monday that spin would have an important role to play at this tournament.