Louis van Gaal’s side knew victory here and at home to Bournemouth this weekend would secure a top-four place – but this loss means Manchester City are two points clear of them going into their final game at Swansea City.
The visitors’ team coach arrived late and was attacked by Hammers fans as it made its way into the stadium, causing the kick-off to be delayed.
When the action got under way West Ham dominated and should have led by more than Diafra Sakho’s goal at the break.
Antony Martial turned the game on its head and had Manchester United in charge with only 18 minutes remaining, first ending a sweeping move then beating Darren Randolph at his near post to put the visitors ahead.
West Ham, however, were not to be denied and two towering headers in the space of four minutes from Michail Antonio and Winston Reid gave them the victory they richly deserved.
Manchester United had their fate in their own hands knowing two victories – here and at home to Bournemouth on Sunday – would assure Champions League football next season.
It was typical of their misfiring season that they squandered this chance with a performance that was for the most part lifeless, only lifted above mediocrity by the brilliance of Martial.
United may have been affected by that late arrival and the delayed kick-off, but their first 45 minutes fell well short of what was needed given how high the stakes were. It was only down to West Ham’s generosity in front of goal that Van Gaal’s side were only 1-0 down at the interval.
And when, against the run of play and thanks to Martial’s excellence, they found themselves ahead with 18 minutes left they were still not good enough to make it count.
The hosts finally took their chances and scored twice in four minutes to once again reveal the flaws in this fragile Manchester United side.
First, Antonio rose high to power home Payet’s cross before Reid headed in another delivery from the Frenchman, though David de Gea got a strong hand to it and should have kept it out.
There were disgraceful scenes outside Upton Park when the late arrival of Manchester United’s team bus was greeted by a mass of West Ham fans who threw bottles at the bus and caused damage.
Inside, the old stadium staged one last hurrah that demonstrated the support and hostility that make it such a special arena – and showed why West Ham will find it almost impossible to recreate this potent combination at the Olympic Stadium.
There were moving scenes before kick-off as a band played Abide With Me as the names and faces of West Ham’s departed greats flashed up on the big screens, with the greatest applause inevitably being reserved – at its conclusion – for England World Cup-winning captain Bobby Moore.
The game itself was played out in a cauldron, a cacophony of noise resounding around Upton Park for the entirety of a thrilling game.
There were some moments when those inside did not cover themselves in glory, keeping the ball from visiting goalkeeper De Gea, which ironically led to the move that brought Martial’s equaliser and then when a fan emerged from the Bobby Moore Stand and got close to the Spain goalkeeper, taunting him before he was dragged away by stewards.
The Hammers wanted to end the Upton Park era with a performance worthy of the old place – and they went out with a bang, producing an outstanding display which hinted at rich promise for what lies ahead.
Slaven Bilic’s side dominated for long spells, playing exciting, fluent football that provided a constant threat.
The Croatian may not have been West Ham’s first choice but he has proved charismatic, astute and someone with a sure touch when it comes to knowing what this club means and demands.
He was in touch with the emotions of the occasion in the closing moments, tie and jacket discarded as he inspired his team to victory, looking almost moved to tears at the end.
West Ham remain on course for the Europa League at the end of a fine season – a deserved reward to take to the Olympic Stadium.