Steve Lomas - with a rare headed goal - and Fredi Kanoute twice gave West Ham a first half lead, but a combination of some poor home defending and slick United counter-attack play resulted in only our third league defeat at Upton Park this season.
Substitute Jermain Defoe scored five minutes after coming on to cut the deficit to 3-4 but another piece of reckless defending by Tomas Repka gave United the 88th minute penalty that David Beckham converted to kill off Hammers' comeback hopes.
Having beaten United 1-0 at Old Trafford in December, West Ham had every chance to complete their first league double over England's top club in 25 years.
Glenn Roeder's men suffered a setback when Trevor Sinclair went down with food poisoning on the morning of the match, but with Michael Carrick restored to midfield after a six-week absence, and Lomas returning after injury to the right of midfield, Hammers went at the Premiership pacesetters from the start.
And the 35,281 crowd had to wait until only the eighth minute for the opening goal. Vladmir Labant, playing in front of Nigel Winterburn wide on the left, was at the heart of some neat build up play before he arced in a cross that Lomas thundered in via Fabien Barthez's right-hand upright.
Lomas goals are rare enough, but headers from the edge of the penalty area past the World Champions' keeper are a collector's item, and no wonder he whipped off his shirt and ran half the length of the Chicken Run in celebration.
Paolo Di Canio, who many felt had a point to prove to Sir Alex Ferguson after his aborted move to United fell through early in the New Year, then went close with an angled drive that flew just past the far post from 20 yards, while Labant fizzed a typically left-footed drive a few feet over the bar from similar distance.
West Ham were in control until they shot themselves in the foot for the first, but by no means the last, time after 17 minutes. Joe Cole's attempted crossfield pass went straight to the recalled Paul Scholes, who, with Hammers' defence wrongfooted, set Beckham into space on the right.
Had any other player been on the ball, Cole's error might have gone unpunished, but the England skipper looked up before delivering a delicate and precise chip from 20 yards over David James and inside the far corner of the net at the Bobby Moore Stand end. His celebrations were not appreciated at that part of the ground, but you had to admire the execution of his finish.
Three minutes later, though, and Hammers had regained the lead. Sebastien Schemmel scampered forward from right back to meet Carrick's lofted pass and his low cross was driven, first time, by Fredi Kanoute past Barthez's left hand from 18 yards.
But just two minutes later, Hammers' defence went to sleep as Beckham curled his freekick onto the head of Nicky Butt - United's smallest player - who, unmarked inside the six-yard box, easily made it 2-2.
Repka missed a good chance to put Hammers back in front again when he got his head to Di Canio's teasing cross to the far post, but steered his effort into the ground and wide, with Barthez nowhere.
It said much about Hammers' lion's share of the possession and chances created that, apart from their two goals, the only other shot on target United managed in the first half was a Roy Keane effort from 20 yards that James comfortably held in stoppage time.
Hammers started the second half the livelier of the two teams but, after 10 minutes of further good possession, another defensive error allowed United to take the lead for the first time.
Repka and Winterburn seemed to have closed down Ole Gunnar Solskjaer on the right by-line. But instead of conceding a likely corner, they allowed the Norwegian striker to turn and pull the ball back for Scholes, who popped up unmarked to sidefoot home for 3-2.
Once ahead, United began to show their class and Ruud Van Nistelrooy, who had been otherwise fairly subdued, went close with a curling shot as the team in white and black stepped up a gear. West Ham's back four began to look shaky and after failing to clear a goalmouth scramble, Solskjaer hooked the ball in from a tight angle on the left to make it 4-2.
Glenn Roeder had no option but to turn to Defoe, although another 10 minutes elapsed before the England under-21 striker - who scored the winner at Old Trafford - finally emerged onto the field, replacing the veteran Winterburn.
As if anyone needed reminding of young Defoe's predatory goalscoring instincts, he was on for just five minutes before scoring his seventh Premiership goal of the season.
Cole released Kanoute into space down the right wing and the Frenchman sent a low cross to the near post area, where Defoe arrived first to tuck the ball past Barthez from four yards.
Suddenly, West Ham were revitalised and an equaliser would have been no less than they deserved for their part in a thrilling encounter.
But the stuffling was knocked out of the players and the crowd when, with three minutes of normal time left, Repka made a rash challenge that brought down Scholes and left referee Mark Halsey no choice but to point to the penalty spot.
Repka had just received his 12th booking of an indisciplined season and this latest error of judgement finally extinguished any lingering hopes of a memorable, late fightback.
On an ultimately disappointing afternoon, there was one consolation for the Hammers as they retained their position in the top half of the table following the failure of the four teams directly below them to win.
Minute-by-minute:
2 - A corner from Labant is flicked on to the far post, where Di Canio is waiting, but the Italian sees his shot blocked by Blanc.
3 - Di Canio collects a return pass from Kanoute inside the box and tries to turn Blanc, who appears to block the ball with his arm. Referee Halsey waves away claims for a penalty.
6 - After Beckham's free-kick is blocked, the England captain's volley back into the danger area is missed by James but drops wide of the post.
7 - GOAL! Hammers get the reward their start deserves, as the returning Lomas becomes an unlikely goalscoring hero. Some excellent football between Kanoute, Di Canio and Labant on the left sees the Slovakian curl in a teasing cross to the danger area, where Lomas outjumps Silvestre to crash a fantastic header in off the crossbar. West Ham United 1 Manchester United 0.
11 - Di Canio - revelling in the spotlight - bamboozles two United players and fires a blistering effort from the edge of the area just inches past the post.
12 - Di Canio's short corner is met on the edge of the area by Labant, who unleashes a left-footed screamer just over the bar.
17 - GOAL. Cole concedes possession in the middle of the field to Scholes, who sets Beckham away on the right. With James frantically back-pedalling, Beckham looks up and places a delightful chip into the far corner of the net. West Ham United 1 Manchester United 1.
19 - Kanoute's blistering shot from the right sails just over the bar.
20 - GOAL! The perfect response from the Hammers as another flowing move results in a beautiful goal. Lomas lays the ball back for Carrick, who releases the overlapping Schemmel on the right. The Frenchman races on before sending a low across along the area that Kanoute strokes perfectly pass Barthez. West Ham United 2 Manchester United 1
22 - GOAL. Amazing scenes at Upton Park as United come back again to equalise immediately. Beckham's dangerous free-kick from the right is met by Butt who, unmarked, heads into the net from six yards out. West Ham United 2 Manchester United 2.
27 - Neville booked for foul on Di Canio.
27 - Di Canio's free-kick from the left is completely missed by Barthez, but somehow headed wide by Repka at the far post.
38 - Hammers attack on the break, as Schemmel receives a pass from Repka and feeds Kanoute, who slices his shot well wide of the target.
43 - Schemmel booked for foul on Solskjaer.
Added time: 2 minutes
45 - Beckham gives a short free-kick to Keane, whose placed shot from 25 yards out is well kept out by James.
Half-time: West Ham United 2 Manchester United 2.
Second Half:
55 - GOAL. With their first real attack of the half, United take the lead for the first time in the match. Solskjaer gains possession on the right and is somehow allowed to squeeze a cross in despite the attentions of Repka and Winterburn, giving Scholes the easiest of tasks to sidefoot the ball past James. West Ham United 2 Manchester United 3.
59 - United are beginning to control proceedings and Keane skips down the right before sending over a low cross that Van Nistelrooy controls and then fires just inches over the bar.
63 - GOAL. The afternoon begins to get worse as United secure a two-goal cushion. Beckham's dangerous cross from the right is only half-cleared by the grounded Repka and Van Nistelrooy sees James block his effort, but the ball squirms loose and Solskjaer is on hand to fire the ball home from just a yard out. West Ham United 2 Manchester United 4.
66 - Another Beckham cross is met this time by Keane, but James pulls off a fantastic relex save and Winterburn blocks Van Nistelrooy's follow-up.
67 - Keane tries again after being played through by Van Nistelrooy, but sidefoots his effort wide of the post.
72 - Repka booked for foul on Scholes.
74 - Substitution for West Ham, Defoe replaces Winterburn.
77 - Di Canio's cross from the left is met by Kanoute, but the Frenchman's header loops high and wide.
78 - GOAL! It's that man Defoe again, as Cole dispossesses Beckham in the centre of the field and releases Kanoute on the right. The Frenchman waits for support before sliding a cross into the six yard box, where Defoe is lurking to glide home yet another poacher's strike and set up a grand finale. West Ham United 3 Manchester United 4.
81 - Solskjaer booked for foul on Cole.
84 - Substitution for Manchester United, Forlan replaces Solskjaer.
86 - Labant's deep free-kick is headed back into the danger area by Defoe and then helped on by Lomas, but Kanoute is just inches away from making contact in the six yard box.
87 - Substitution for Manchester United, Fortune replaces Van Nistelrooy.
88 - United are given a chance to wrap up the points after Repka is adjudged to have fouled Scholes in the area by referee Halsey.
89 - GOAL. Beckham blasts home from the penalty spot to finally kill off the Hammers' hopes of a revival. West Ham United 3 Manchester United 5.
Added time: 3 minutes.
Full-Time: West Ham United 3 Manchester United 5.