Morocco's goals were scored by Amine Bidouri, Zouhir Jabbari, Badr El Kraichly and Reda Zahraoui.
Morocco had beaten El Salvador in their opening match, before losing to Switzerland in their second game.
On the final day, the Moroccan squad took advantage of Switzerland's defeat by El Salvador to take first place with 6 points and win the title.