Imad Wasim scalped two wickets and then went on to score an unbeaten 49 as Pakistan beat Afghanistan to keep their semifinal hopes alive.