At Al Bayt Stadium, Theo Hernandez put France ahead early, and then Randal Kolo Muani scored in stoppage time to seal a 2-0 victory and a spot in the World Cup final.
France is still in contention to repeat as world champions, and they'll face Lionel Messi and Argentina in the final.
Following Hernandez's fifth-minute opener, Walid Regragui's side responded superbly, pinning back the world champions for significant periods in a display of considerable courage and skill. Morocco has been the surprise package of Qatar 2022.
Kolo Muani, a striker for Eintracht Frankfurt, emerged as an unlikely hero for France by scoring with his first touch after Kylian Mbappe had a shot stopped in the 88th minute.
Before this encounter, Morocco had only conceded once in the tournament, and that was an own goal, as they made history as the first African team to reach the World Cup quarterfinals.
Nayef Aguard, Noussair Mazraoui, and Romain Saiss were all declared fit to play, however Aguard withdrew from West Ham during the pregame warmup, while Saiss, the team captain, was taken out in the first half due to obvious fatigue.
This doubt likely had a role in the disorganised first half of France's match, in which Antoine Griezmann capitalised on a mistake by Jawad El Yamiq to feed Kylian Mbappe. Hernandez was alert to the opportunities presented when the PSG star had an initial shot blocked and a second attempt loop up off Oliver Giroud, and he converted with an acrobatic finish.
El Yamiq almost made up for his mistake with an overhead kick that thumped the base of the post, and Giroud hit the upright as Saiss' thigh gave out. Hugo Lloris had already made a save at full stretch from Azzedine Ounahi.
Illness sidelined Dayot Upemacano's replacement, Ibrahima Konate, who made a couple of last-ditch clearances, and Mbappe's quick feet opened up space for a half-blocked shot that dropped pleasantly for Kolo Muani, who had only been on the field for 44 seconds.
The remarkable run by Morocco will be remembered for much longer.