Super-sub Marcus Rashford struck a dramatic stoppage-time winner as Manchester United broke West Ham hearts and lifted the roof off Old Trafford.
In the Carabao Cup earlier in the season David Moyes led the Hammers to their first win at the Red Devils since 2007 and he looked set to leave with a potentially vital point in the race for Champions League qualification.
But United dug deep and secured victory with virtually the last kick of the game as Edinson Cavani crossed for fellow substitute Rashford to score in front of a rocking Stretford End to seal a 1-0 win.
It was a memorable end to what looked set to end in a drab goalless draw between two sides that failed to muster a shot on target between them in the first half.
Cristiano Ronaldo went close to connecting a with a fine cross and saw penalty appeals ignored in that opening period, with Ralf Rangnick throwing caution to the wind with his late attacking substitutions.
West Ham nearly capitalised as they pushed top-heavy United, only for the stars to align as Rashford turned home.
After a video assistant referee review for offside, the goal was awarded as Rangnick celebrated consecutive wins for the first time in charge.
United usurped West Ham in fourth after the breathless end to what was largely forgettable encounter.
Rangnick’s only change to the 3-1 win at Brentford saw captain Harry Maguire return in place of Victor Lindelof, who was with his family after a traumatic break-in at his house during that midweek fixture.
The skipper started sharply with strong challenges on in-form Jarrod Bowen and Michail Antonio, with Mason Greenwood wasting an opportunity on the break at the other end.
Ronaldo attempted to atone for a poor free-kick with a drilled shot that was charged down.
United were producing some crisp passing as they patiently probed and the veteran nearly reached a superb Bruno Fernandes cross at the end of one such move.
The hosts were controlling proceedings against a side that were happy to sit back and play on the break, albeit their play was too rushed and ineffective when they attempted to.
Ronaldo screamed for a penalty after going down under pressure from Kurt Zouma when attempting to reach a ball. He was not impressed when referee Jon Moss told him the VAR had cleared the on-field decision.
The 36-year-old still looked unhappy as the players trudged off at half-time, ending a half in which play had become scrappier as it wound down.
The first shot on target of the day arrived in the 49th minute as the ball bounced kindly for Fred, who forced a fine save out of Alphonse Areola on his first Premier League start for the Hammers.
West Ham’s first corner of the game followed soon after and United looked predictably unsteady. Able to clear the initial cross, they left Jarrod Bowen to get the loose ball and his shot rippled the side netting.
The Red Devils had not scored from a corner all season but they came close when Raphael Varane rose to meet an Alex Telles set piece with a powerful header just over.
Anthony Elanga hooked wide shortly before Marcus Rashford replaced him, providing new energy to a frontline struggling to create opportunities.
Fernandes and Telles had wayward efforts as United pushed, with Rangnick turning to Cavani and wantaway Anthony Martial as the match entered the final stages. There were a smattering of boos for the latter.
West Ham nearly snatched victory at the death as Tomas Soucek all too easily got free to glance a Bowen corner across the face of goal.
David De Gea had to be alert to prevent a Rice cross deflecting in at the near post, with Martial unable to get a clean shot away on the turn in stoppage time.
But for all their faults, United have regularly shown their ability to fight in recent years.
In one last roll of the dice, they charged forwards and Cavani crossed for Rashford to turn home at the far post. The VAR checked a potential offside but there was to be no last-gasp reprieve for Moyes’ men.