Morocco qualified for the last 16 of the 2022 World Cup after beating Canada 2-1 in the decisive match of Group F.