Diafra Sakho came in from the cold to hit a last-minute winner and dig West Ham manager Slaven Bilic out of a hole.
The London Stadium was almost in open revolt following an insipid 89 minutes from the home side against Swansea.
But Sakho, who if he had got his way on transfer deadline day would now be in France playing for Rennes, climbed off the bench to secure a 1-0 win and bail out his boss.
Even Bilic had branded this a "must-win" game, and he should know - so precarious has his position looked at times that West Ham have had about 10 in the last 12 months.
The credit that the Croatian built up during the final season at Upton Park seems to have evaporated, if the boos which rang round at his decision to substitute Javier Hernandez are anything to go by.
Yet West Ham are somehow now out of the bottom three, and with games against Brighton, Burnley and Crystal Palace coming up, Bilic will feel they can climb further away from trouble.
The Hammers did actually almost open the scoring early on, Lukasz Fabianski at full stretch to palm Michail Antonio's effort wide.
In keeping with the rest of a truly awful first half it was a scrappy, scuffed shot which looped up off the turf, but it still required a decent save.
At the other end Wilfried Bony checked Joe Hart was still awake with a 25-year drive which the England keeper extravagantly palmed wide.
The fact that it was only Swansea's 11th shot on target this season illustrated what little attacking threat West Ham were up against - and yet the visitors were in total control.
It was worse than the sort of fare served up by Sam Allardyce which irked the fans so much and eventually cost him his job, to be replaced by Bilic.
There was even a smattering of boos from some of the supporters who had managed to stay in their seats until the half-time whistle.
After the break Antonio sent in a deep cross which Andy Carroll, stretching at the far post, just failed to get a touch to.
Bilic sent on fit-again playmaker Manuel Lanzini, for the ineffective Mark Noble, on the hour mark in a belated attempt to inject some life into proceedings.
Yet still Swansea posed the greater threat, with Martin Olsson sending a curling effort narrowly wide.
Bilic turned to Sakho - for Hernandez - and Arthur Masuaku for inspiration, and it eventually arrived.
Carroll had already turned one Masuaku cross against a post and when the winger whipped in a second, Sakho arrived on cue.
The Senegal striker, yet to start a Premier League game since his deadline day shenanigans, slid in at the far post to snatch a scarcely deserved, but potentially huge, three points.