Two late goals earned Morocco a hard-fought 4-2 win against Haiti in their final Group C game, which saw them finish as runners-up.