Dennis Oliech's stoppage-time goal sealed a valuable win for Ajaccio after they came from behind to beat Montpellier in a game which saw both sides finish with 10 men.
Oliech headed Ajaccio ahead with only seconds left on the clock after Andy Delorte had cancelled out Anthony Mounier's strike for Montpellier.
It was a dramatic game which saw Ajaccio go close three times in the first half before defender Fousseni Diawara was shown a red card early in the second after he brought down Montpellier striker Souleymane Camara and also conceded a penalty.
Younes Belhanda missed the resulting spot-kick as he tried to lob Guillermo Ochoa, the Ajaccio goalkeeper alert to his plan and able to make an easy save.
Montpellier did, however, score six minutes later through a great counter-attacking move started by Henri Bedimo and finished by Mounier.
Bedimo raced down the left and freed Mounier at the far post, who had been left completely unmarked and coolly slotted the ball home.
Ajaccio refused to lie down and soon forced Montpellier to clear the ball off their own line, before they were awarded a penalty with 10 minutes remaining.
Montpellier defender Abdel El Kaoutari hauled down Delorte inside the area and was shown red, with the Ajaccio substitute striker stepping up to shoot low into the left-hand corner and level the score.
In a final twist, Ajaccio claimed all three points when Oliech headed the ball in from close range after a pinpoint cross from Delorte.
The win leaves Ajaccio four points clear of the relegation zone with four games left to play, while Montpellier remain in eighth.