Marlon Harewood handed West Ham a dream finish to their remarkable season when he fired them into the FA Cup final and into Europe.
The striker blasted home with just 12 minutes remaining to end Middlesbrough's hopes of a famous cup double and snatch a UEFA Cup place for the new campaign regardless of what happens against Liverpool in Cardiff on May 13.
Alan Pardew's promoted side mounted a concerted fightback after a lacklustre first-half display, and went close when the impressive Dean Ashton headed against the crossbar on 55 minutes.
But the Hammers' record signing was to play a major role in the game's decisive moment, heading down an Anton Ferdinand long ball for Harewood to hammer a shot past substitute goalkeeper Brad Jones.
Jones was only on the pitch because Mark Schwarzer had suffered a fractured cheekbone in a first-half clash with Ashton, an injury which could end his season and cause the Australia camp concern ahead of the World Cup finals.
But after seeing Aiyegbeni Yakubu, substitute Massimo Maccarone and Chris Riggott waste glorious opportunities to level at the death, Boro headed into Thursday night's UEFA Cup semi-final decider with Steaua Bucharest knowing their season will be over if they cannot overturn their 1-0 first-leg deficit.
Much has been said and written in the last few weeks about Steve McClaren and his candidacy for the soon-to-be-vacant England job, and it appears he has both his fans and his critics inside and outside Soho Square.
However, he has founded his reputation on his tactical sense, and he once again got it just right before the break as he sought the right personnel and system for his side's 58th and perhaps most important game of the season.
It may have been a gamble to select skipper Gareth Southgate after he was ruled out of the game in Romania with an ankle injury, but in teaming the 35-year-old up with Riggott and Franck Queudrue in a three-man back line, he laid the foundation for an enterprising first 45 minutes.
With Stuart Parnaby and 19-year-old Andrew Taylor operating as wing-backs, Boro had genuine wit, particularly down the left where Taylor combined well with Stewart Downing to give makeshift full-back Ferdinand a tough time.
George Boateng's energy in the middle of the field and Jimmy Floyd Hasselbaink's foraging helped Boro to regularly put the Hammers under pressure, although they too often failed to test Shaka Hislop.
James Collins had to hack away a sixth-minute Hasselbaink header and Fabio Rochemback and Downing both forced Hislop into smart saves in quick succession as the Teessiders started brightly.
However, Rochemback and Hasselbaink both shot wastefully into the defensive wall from promising positions, and as West Ham belatedly found their feet, it was they who started to threaten.
Pardew's side had initially opted to aim a series of high balls towards Ashton and attempt to pick up the pieces but having seen that policy fail, they began to use the far more productive midfield route of Nigel Reo-Coker, Matthew Etherington and Yossi Benayoun.
Boro were dealt a blow on 41 minutes when Schwarzer was forced to leave the field, and replacement Jones saw Benayoun fire over when he might have done better within three minutes of his arrival.
Rochemback and Yakubu both went close deep into injury time, but the sides remained locked together as they left the pitch at the break.
The Hammers emerged obviously having decided to make their big push and Boro had to defend with the kind of resilience which had previously got them through 23 cup ties this season.
But the Teessiders almost caught their opponents on the break on 52 minutes only for Rochemback to waste Hasselbaink's good work with a scuffed cross which was easily cut out by Danny Gabbidon.
Harewood blazed over two minutes later after creating a half-chance for himself with a towering jump, but Ashton was denied by the woodwork after meeting Benayoun's 55th-minute corner with a firm header.
The £7.25million strike was posing all kinds of problems and Jones had to save from another header four minutes later with McClaren's men visibly wilting.
Reo-Coker blasted a long-range effort inches wide with Jones beaten, and although Hasselbaink headed wide from a Downing cross, the Londoners sensed the game was there for the taking.
Boro rallied with Rochemback testing Hislop with a dipping 74th-minute drive, but West Ham went in front four minutes later.
Ashton climbed well to head down Ferdinand's long ball and Harewood took a touch before blasting a left-foot shot into the back of the net.
Hislop pulled off a fine save to keep out Queudrue's 84th-minute free kick after Hasselbaink had been felled by Collins just outside the box, but there were even bigger scares to come.
Hasselbaink's 89th-minute cross was headed back by Riggott to Yakubu in front of goal, but the striker completely missed his kick and Maccarone drove the rebound high over, and Riggott dragged the shot across goal in the fifth minute of injury time as the chance of salvation came and went.