After Lacazette opened the scoring in the 31st minute, Montpellier's Elye Wahi scored four unanswered goals to put his side 4-1 up after 55 minutes.
Goals from Lacazette and Dejan Lovren then reduced the deficit with Lacazette equalising in the 82nd minute.
And the ex-Arsenal forward netted the winner from the spot seconds from time.
Lyon were awarded the penalty in the eighth minute of stoppage time after the video assistant referee adjudged Christopher Jullien to have brought Lacazette down in the area.The result saw Lyon stay seventh, three points off a Europa League qualification spot with four matches remaining in Ligue 1.
Montpellier remained 12th, 11 points clear of the relegation places.