David De Gea saved a penalty in the fifth minute of injury time taken by West Ham substitute Mark Noble, who was sent on purely to take the kick, as Manchester United held on for a 2-1 victory at the London Stadium.
A penalty was awarded via a VAR check after Jarrod Bowen saw his cross strike the outstretched arm of Luke Shaw.
Minutes earlier the failure of West Ham to sign last season's loan star Jesse Lingard came back to haunt them as the England forward curled an unstoppable strike into the top corner in the 89th minute.
Rangers seal deal to sign Diallo on loan from Manchester United
The Hammers went in front on the half hour mark when Said Benrahma aimed a shot from 20 yards to David De Gea's left only for it to be deflected by Raphael Varane just inside the goalkeeper's right hand post.
The lead lasted just five minutes before Bruno Fernandes' fine inswinging cross from the left saw Cristiano Ronaldo beat the offside trap and though Lukasz Fabianski saved the initial attempt on the volley, he could do nothing to stop the rebound nestling in the goal behind him as the Real Madrid legend scored for the third game in succession.
The Red Devils were overall worthy victors with Fernandes, when the game was goalless, seeing a shot tipped onto the post by Fabianski, who also raced from his line to deny a great chance for Ronaldo in the second half.
Had West Ham grabbed an equaliser United would have been particularly sickened as their Portuguese legend went to ground claiming a penalty three times in the latter stages of the game, the last of which generated a particularly strong appeal after a challenge from Kurt Zouma, but on all occasions referee Martin Atkinson waved away his protests.
Manchester United celebrate Jesse Lingard's goal
Image credit: Getty Images
TALKING POINT - WHAT A GAME!
What to choose as a talking point for this game? Ronaldo's penalty box presence on the day England's greatest ever goalscorer left this mortal coil - incredibly with over 200 goals since turning 31, Ronaldo might even end up matching Jimmy Greaves' career goalscoring total just counting those scored after the age Dagenham's finest retired.
Or we could look at Jesse Lingard, whose confidence was regained and position as an England international restored at West Ham last year, scored a brilliant winner after a week in which he once again became the Manchester United whipping boy after his error led to Young Boys' winner against United in the Champions League.
But these were trumped at the end of the match with the most controversial of decisions from David Moyes to bring on club captain Mark Noble, the team's penalty taker who had scored his last ten spot kicks, but was surely not warmed up and went on to miss the penalty. It was an incredibly bold call from the former Manchester United manager but surely the wrong one, not to dismiss David De Gea's efforts diving to his left to push away the shot.
MAN OF THE MATCH - LUKASZ FABIANSKI
There were good outfield performances on either side, Jarrod Bowen and Said Benrahma were a persistent threat for West Ham, while Bruno Fernandes produced a number of typically astute key passes and Ronaldo was his typical irrepressible penalty box presence.
However, the former Arsenal goalkeeper made a number of saves during the match and two of these, from Fernandes and Ronaldo were absolutely world class. The late drama is what will be most remembered from the match but there would not have been jeopardy in the game at that stage but for the Polish keeper's earlier brilliance.
West Ham: Fabianski 8; Coufal 6, Zouma 6, Ogbonna 6, Cresswell 6; Soucek 7, Rice 7; Bowen 7, Benrahma 7, Fornals 6; Vlasic 6. Subs: Yarmolenko 6, Lanzini N/A, Noble 0
Man Utd: De Gea 7; Wan Bissaka 7, Varane 6, Maguire 6, Shaw 6; Fred 6, McTominay 6; Greenwood 7, Pogba 6, Fernandes 7; Ronaldo 7. Subs: Sancho 5, Lingard 7, Matic N/A
28' OFF THE POST! Shaw's corner finds Fernandes at the back post and he strikes a bullet on the volley with his left foot but Fabianski does superbly to tip the ball on to the post.
31' GOAL! West Ham 1-0 Man Utd (Benrahma): Benrahma shoots from the edge of the box aimed towards the top right corner but it deflects off Varane leaving De Gea with no chance, sending the ball way to the keeper's right, inside the left hand post.
35' GOAL! West Ham 1-1 Man Utd (Ronaldo): Ronaldo's shot from Fernandes' cross is saved by Fabianski but he follows up to slam the rebound home.
89' GOAL! West Ham 1-2 Man Utd (Lingard): Lingard has time to turn onto his right foot in the box and curls an unstoppable effort past Fabianski into the top right hand corner.
90+2' West Ham appeal for a penalty after Bowen's cross strikes the outstretched arm of Luke Shaw. PENALTY! A VAR review sees a penalty given.
90+5' Noble comes on for Bowen. Coming on to take the penalty?
90+5' SAVED! De Gea saves the penalty diving to his left. WOW.
After Martial's exit, Manchester United need to continue their clearout
Rangers agree loan deal with Man Utd for Diallo - reports