Monaco took the lead on three occasions but were pegged back every time in an enthralling match at Stade Velodrome, before Lemar's 113th-minute strike finally proved decisive.
The visitors 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 their 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.
3-4 - Marseille 3-4 Monaco has seen as many goals scored as shots saved (7). Efficient.— OptaJean (@OptaJean) March 1, 2017
5 - @KMbappe has scored in each of his last 5 starts in all comps (7 goals). Phenomenon.— OptaJean (@OptaJean) March 1, 2017
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 leaders Monaco subsequently see their bid for a first Coupe de France crown since 1991 continue, while Marseille – who were runners up last year – crash out to cap a miserable four days that also saw them thrashed 5-1 by Classique rivals Paris Saint-Germain.