Monaco took the lead on three occasions but was pegged back every time in an enthralling match at Stade Velodrome, before Lemar's 113th-minute strike finally proved decisive.
The visitor led for the first time midway through the first half when Joao Moutinho's deflected free kick bounced off the post and in off the chest of goalkeeper Yohann Pele, who was credited with an own goal.
But Dimitri Payet scored the goal of the night - an exquisite left-footed strike into the bottom corner from Florian Thauvin's cross – just before the interval.
Monaco restored its lead through Kylian Mbappe's deft finish on 65 minutes, but Remy Cabella tapped in after a cutback from Hiroki Sakai with six minutes to play, sending the tie to extra-time.
The additional period was no less dramatic, Monaco striking first when a fast break cut open the Marseille defence, leading to Mbappe squaring for Benjamin Mendy to convert.
Cabella raced on to Gregory Sertic's flick-on and found the bottom corner to grab his second of the night and seemingly send the tie towards penalties.
But Lemar had the final word just 142 seconds later, sealing the most remarkable of victories when he found the top corner from Mendy's delivery.
Ligue 1 leader Monaco subsequently sees its bid for a first Coupe de France crown since 1991 continue, while Marseille – which was the runner up last year – crash out to cap a miserable four days that also saw it thrashed 5-1 by Classique rival Paris Saint-Germain.
Monaco will have to wait to face PSG after the pair avoided each other in the quarter-final draw:
Angers v Bordeaux
US Avranches v PSG
Monaco v Bergerac or Lille
EFC Frejus Saint-Raphael v Guingamp