Said Benrahma had fired West Ham into the lead with a sizzling strike before Wilfried Zaha hauled Palace level before the interval.
There was VAR controversy 10 minutes from the end when Michail Antonio went down after being tugged by Marc Guehi and referee Paul Tierney gave a penalty, only to overturn his decision after consulting the pitchside monitor.
Instead, with the clock running down, Antonio wastefully chipped a cross into the arms of Palace keeper Vicente Guaita and within seconds, the visitors had broken up the other end and scored.
It meant West Ham’s six-match winning streak at home came to an end, while Palace secured their first away win in the Premier League this season.
West Ham were second best for much of the match but went ahead in style after Benrahma picked up the ball 25 yards out.
Manchester United 1 West Ham 0 - player ratings
The Algerian winger, making only his sixth Premier League start of the season, shrugged off Jordan Ayew before unleashing an unstoppable drive past Guaita.
It was a glorious strike but the West Ham defence undid all his good work with a horror show five minutes before half-time.
There was no danger as Lukasz Fabianski rolled the ball to Craig Dawson, who in turn sent it towards Thilo Kehrer on the right wing.
But the Germany international was robbed by Eberechi Eze and Zaha outmuscled Dawson before lashing the ball past Fabianski.
Palace were carrying by far the greater threat at the start of the second half with both Eze and Olise curling shots narrowly wide.
Frustration in the stands was creeping in and when David Moyes made a double change on the hour, his decision to bring off Benrahma was met with a chorus of boos while the substitution of the misfiring Tomas Soucek was loudly cheered.
The home side improved marginally and Jarrod Bowen’s corner was headed straight at Guaita by Kehrer before Declan Rice blazed over.
Then, with 10 minutes remaining, Antonio did brilliantly to turn Joachim Andersen on the halfway line before bulldozing his way into the area.
He charged past Guehi, who seemed to have the slightest hold of the striker’s shorts before Antonio flung himself to the ground.
A lengthy VAR check resulted in Tierney looking at the replays and ruling out the spot-kick.
Then, in stoppage time, Guaita caught Antonio’s weak cross and started the counter-attack that finished in Olise’s dramatic winner.