The unexpected outcome can partly be explained by Morocco coach Herve Renard making numerous substitutions in the first of two friendly fixtures before heading to Egypt for the finals.
Musa Barrow, who plays for Serie A club and 2019/2020 UEFA Champions League qualifiers Atalanta, scored the match-winner on 27 minutes at Stade de Marrakech.
It was the second victory for the lowly ranked Gambians over a Cup of Nations qualifier within six days after they defeated Guinea 1-0 last Friday in the same city.
Morocco are in Group D with fellow former champions the Ivory Coast and South Africa and rank outsiders Namibia.
The group is considered the toughest of the six to qualify from and only the winners and runners-up are guaranteed places in the round-of-16 knockout stage.