Ghana striker Abdul Majeed Waris struck the winner two minutes from time as Valenciennes earned a morale-boosting win over Nice to keep their survival hopes alive in the French top-flight.
Tongo Doumbia had put Valenciennes ahead after 26 minutes but it seemed they would have to settle for a point after Neal Maupay levelled in the 75th minute.
However, Majeed's late goal gave the hosts only their fourth win of the season, putting them within four points of safety.
Prior to kick-off the form book clearly pointed to a Nice win, with the visitors - 4-0 winners in the reverse fixture - in good form having won four of their last six while Valenciennes were coming off the back of two consecutive losses.
But it quickly became apparent that Valenciennes posed significant dangers as David Ospina was forced into early saves from Maor Melikson's clever chip before turning away a low drive from Gregory Pujol.
The hosts led midway through the first half when Majeed led a swift counter-attack, picking out Doumbia to head the ball beyond the reach of Ospina.
They almost doubled their lead three minutes before half-time when David Ducourtioux advanced down the right and then found Doumbia, but Romain Genevois made a vital intervention.
The hosts continued to dominate in the second half, and wasted a fine chance just two minutes after the restart when Carl Medjani could not get his header on target having been left unmarked to meet Melikson's free-kick.
Ospina then kept out a Pujol header before reaching to push clear Rudy Mater's long-range free-kick.
It was entirely against the run of play that Nice levelled when Christian Bruls teed up Maupay to finish clinically.
But Valenciennes had the final word when Majeed cut in from the left before powering a shot beyond Ospina to earn a potentially vital win.
The move started when Romain Genevois was robbed by David Ducourtioux who fed Waris - in full flight, the Ghanaian deftly stepped inside Mathieu Bodmer before smashing a shot beyond Ospina to spark delirium at the Stade du Hainaut.