Afghanistan earned a narrow eight-run win against England in the Champions Trophy, sending them packing from the tournament.