Sloan Privat's injury-time header came back off the crossbar as St Etienne hung on for a victory that keeps them firmly in the race for European football while putting further pressure on relegation-battling Sochaux.
St Etienne twice took the lead, Fabien Lemoine's powerful 76th minute shot restoring their advantage five minutes after Edouard Butin cancelled out Pierre-Emerick Aubameyang's first-half opener, but should have been out of sight only for Aubameyang to miss a late penalty.
That kept hope alive for Sochaux until Privat's header crashed back off the crossbar in the third minute of stoppage time.
The result leaves St Etienne in sixth, one point off fourth-placed Bordeaux, while Sochaux hover just two points above the drop zone.
Aubameyang had given St Etienne the lead in outstanding fashion after 22 minutes, lashing a volley into the top corner of the net after being released by Josuha Guilavogui.
He then almost turned provider as Simon Pouplin did well to keep out Yohann Mollo's shot, but those were the only real chances of the first half.
Most of the action came after the break. St Etienne might have doubled their lead just after the hour mark, with Guilavogui preying on some poor Sochaux defending before curling in a shot that Pouplin did well to keep away.
Instead Sochaux levelled as Butin broke down the right and then cut inside to beat Stephane Ruffier and roll the ball into the empty net.
But St Etienne swiftly responded as Renaud Cohade's cross found Lemoine and his powerful shot found the net with the aid of a deflection.
They should have sealed it nine minutes from time after Sebastien Roudet handled, but Aubameyang's penalty did not have the power to beat Pouplin and he fluffed the rebound.
That gave Sochaux hope - but Privat's header was kept out by the crossbar deep into injury time.