While the entire 90 minutes at the Al Thumama Stadium were competitive, Morocco overcame a slow start to create the better moments in the final third, and strikes from Abdelhamid Sabiri and Zakaria Aboukhial earned the Atlas Lions just their third victory in the history of this tournament.
While Morocco now sit in first spot with four points, Belgium have been left with work to do to qualify for the last 16, their fate only remaining in their own hands if Croatia fail to defeat Canada.
Belgium also miss out on a record-equalling 16th successive match without defeat in the group stages of this competition, this setback representing their first loss since the 1994 edition.
Unlike in their previous match against Canada, Belgium showcased their talent during the early stages with Michy Batshuayi completing a free-flowing team move with a shot which was diverted behind by Munir Mohamedi.
Belgium's dominance continued without the Red Devils creating clear-cut chances, although Amadou Onana should have done better with a header after beating Mohamedi to a corner.
Morocco finally laid a glove on their opponents just after the 20-minute mark, Hakim Ziyech sending a swerving effort from distance marginally over the crossbar.
As the first half progressed, Morocco were becoming the more threatening team, although Achraf Hakimi failed to take advantage of finding space in the penalty area by lashing a shot well off target.
Walid Regragui's side thought they had taken the lead with the final action of the opening 45 minutes when Ziyech's free kick evaded everyone and was diverted into the net by Thibaut Courtois.
However, Romain Saiss, despite not touching the ball, was marginally offside and impacted the situation by running across Courtois's line of sight, leading to the goal being chalked off.
Both nations showed intent after the restart, Ziyech initially bringing a routine save out of Courtois before Eden Hazard created a chance for himself on the right-hand side of the penalty area before forcing Mohamedi into a save at his near post.
Back up the other end, Sofiane Boufal was the next to go close, just failing to get enough curl on his effort aimed for the far corner, while Dries Mertens should perhaps have done better with a shot from 20 yards shortly after being introduced as a substitute.
The deadlock was finally broken with 16 minutes remaining, and in similar circumstances to the earlier disallowed goal. On this occasion, Saiss remained onside before moving across Courtois, and Abdelhamid Sabiri's cross-cum-shot was able to head straight into the far corner.
In response, Roberto Martinez introduced Romelu Lukaku into the action ahead of his previously-planned return date from injury, but it was a header from Jan Vertonghen which almost brought Belgium level, the ball bouncing narrowly wide of the far post.
As Belgium pushed men forward, more space opened up at the other end of the pitch, and the African nation exploited that with a match-clinching second in added-on time.
Tremendous work from Ziyech created space for himself inside the area and after pulling the ball back for Zakaria Aboukhlal, the substitute did the rest with a first-time finish into the roof of Courtois's net, sparking jubilant scenes on the pitch and in the stands.