South Africa spinner Imran Tahir struck twice in one over as Afghanistan's batting collapsed at the ICC World Cup.