Jesse Lingard scored a late winner for Manchester United in a dramatic finish at the London Stadium that saw Mark Noble miss an injury-time penalty for West Ham with his first touch after coming on as a substitute.
West Ham took the lead after half an hour when Said Benrahma's strike from outside the area took a huge deflection off Raphael Varane, giving United goalkeeper David De Gea no chance.
Cristiano Ronaldo levelled for the visitors - with his fourth goal in three games since returning to the club - when he finished from a couple of metres out after Hammers goalkeeper Lukasz Fabianski had spilt the Portuguese's initial shot.
Fabianski made a string of good saves in the first half, the best was a fingertip effort to turn Bruno Fernandes' shot on to the post.
The match seemed to be heading for a draw when Lingard - who enjoyed a hugely successful loan spell with the Hammers last season - cut inside on to his right foot and curled a perfect strike into the top corner in the 89th minute.
But that was not the end of the drama, though. Luke Shaw was rightly adjudged to have handballed in the box after a VAR check handing West Ham the chance for an injury-time leveller. United were furious - but more because that Ronaldo had twice been denied ligitmate claims for a penalty, rather than anger at the Shaw decision.
But Hammaers club captain Noble came on to the pitch to take the penalty only to see De Gea guess the right way and comfortably save his spot kick.
It was West Ham's first defeat of the season and leaves them in eighth place in the table with eight points from five games. Ole Gunnar Solskjaer's side are unbeaten and sit joint top of the table with four wins and a draw — although they could be overtaken by Chelsea if they win at Tottenham in the game later on Sunday.
Player ratings from the matches can be seen in the picture gallery above. To view the next image, click on the arrows or swipe if on a mobile device.