Morocco jeopardised Belgium's World Cup hopes as Abdelhamid Sabiri and Zakaria Aboukhlal's late goals secured a surprise 2-0 triumph in Doha on Sunday.
Belgium, third in Russia four years ago, could have qualified for the last 16 with victory but instead produced another insipid display after their fortunate opening win over Canada.
Substitute Sabiri was the hero thanks to a 73rd-minute free-kick which Thibaut Courtois allowed to bounce in at his near post, before Aboukhlal grabbed a second in stoppage time.
The tens of thousands of Morocco supporters responded by cheering their team home at a raucous Al Thumama Stadium.
Morocco replace Belgium at the top of Goup F and know they will qualify for the knockout phase for the first time since 1986 if they can avoid defeat against Canada on Thursday.
Belgium, the world's second-ranked side, will have to beat 2018 runners-up Croatia to be sure of going through.
Roberto Martinez's ageing side have reached at least the quarter-finals of each of the past four major tournaments.
Belgium, whose captain Eden Hazard has admitted are not as good as in 2018, lacked spark and were made to pay by inspired opposition.
Morocco were dealt a blow after the national anthems when goalkeeper Yassine Bounou appeared to gesture he would not be able to play.
The experienced Munir El Kajoui was sent out in his place.
The Atlas Lions fans vastly outnumbered their Belgian counterparts and breathed a sigh of relief when the Europeans almost grabbed a fourth-minute lead.
Hazard played in Michy Batshuayi whose effort from a tight angle was kept out by Munir.
Belgium dominated the early exchanges but Morocco did manage a shot at goal when Hakim Ziyech fired over from distance.
The African side continued to grow into the contest and Selim Amallah, who was born in Belgium, volleyed into the stands before Achraf Hakimi blazed a presentable chance off target.
The crowd erupted in raucous celebration when Ziyech's free-kick flew all the way into the net in first-half injury time.
But the goal was ruled out after a VAR check, as Romain Saiss was leaning just offside and the former Wolves defender was in 'keeper Courtois' eyeline.
Both teams started the second period brightly, with Ziyech shooting straight at Courtois and Hazard bringing a save from Munir at his near post.
Sofiane Boufal almost broke the deadlock in the 57th minute after a jinking run but bent the ball narrowly wide of the far post.
Martinez made two changes on the hour mark, replacing the ineffective Hazard with Dries Mertens and bringing on Youri Tielemans for Amadou Onana in midfield.
Mertens almost made an immediate impact when his strike from just outside the area was beaten away by Munir.
The deadlock was finally broken with 17 minutes remaining as Sabiri's free-kick from near the touchline, much like for Ziyech's ruled out goal, caught out a flat-footed Courtois.
Martinez threw on Romelu Lukaku, expected to miss the game injured, in a desperate attempt to get back into the match.
But Belgium had long since run out of ideas and it was Morocco who scored the second goal of the game.
Brilliant play by Ziyech created space in the area for Aboukhlal to lash the Chelsea winger's pull-back into the roof of the net.
Any tension in the stands was lifted and the Morocco fans were able to celebrate their first World Cup win in 24 years. (AFP)