After seeing Dwight Yorke give Blackburn Rovers a 38th minute lead, Hammers hit back with an equalising penalty from returning skipper Paolo Di Canio just under the hour mark.
And with just 30 seconds of normal time to play, substitute Jermain Defoe snatched a brilliant winner that lifts the East Londoners off the bottom of the table, West Bromwich Albion having lost tonight at home to Charlton Athletic.
The capacity crowd were ecstatic and a relieved Glenn Roeder also leapt for joy, both hands punching the air, as he celebrated what he must hope will prove a massive turning point of the season.
Hammers, still licking their wounds following Sunday's shambles in the FA Cup at Old Trafford, were worth their win, which was Roeder's reward for taking fairly drastic action with his team selection.
Out of the side slaughtered 6-0 at Manchester United were defenders Gary Breen and Scott Minto, while Trevor Sinclair was dropped to the bench and Christian Dailly didn't even make the squad.
The beleaguered boss gave home debuts to Les Ferdinand - in for the rested Defoe - and young right-back Glen Johnson, who started his first match for the club.
For the first time this season, Roeder paired Ian Pearce and Tomas Repka together in the centre of defence, with veteran Nigel Winterburn reclaiming the left-back berth from Minto.
Ferdinand showed his value in the air when he headed Lee Bowyer's cross at Rovers keeper Brad Friedel after eight minutes, while the American number one was tested more fully by a rasping drive from Di Canio.
Hammers' only other threatening moment of a patchy first half came when Steve Lomas latched onto a loose ball in the box, but could only toe-poke his shot wide.
Apart from a hairy moment when David James came out rather rashly, which ended with Bowyer heading the ball off his own goal-line, Rovers had not troubled the Hammers before they scored.
Winterburn, showing the kind of fight that had been sadly lacking in Manchester, had trouble containing the pace and trickery of Keith Gillespie and the opening goal followed his trip on the Irish winger.
David Thompson curled the free-kick towards the far post, where the unmarked Yorke even had enough time to mis-control the ball and still prod the ball over the line from inside the six-yard box.
But the Upton Park crowd bit their tongues and didn't turn against the men in claret and blue, who, not surprisingly were edgy at times. Possession was conceded too easily and there was a tendency to hit too many long, hopeful balls.
Di Canio, who hadn't played since December 2, made a big difference, though. The Italian kept the ball better than any of his team-mates and, after receiving a pass from Joe Cole, he won the penalty himself by sucking Andy Todd into a reckless tackle on the left-hand edge of the box after 58 minutes.
The Bobby Moore Stand held its breath but they needn't have worried, as Di Canio calmly placed his spot kick into the roof of the net.
Roeder underlined his desire for all three points by immediately replacing the willing Ferdinand with Fredi Kanoute, back after his abortive comeback attempt on Boxing Day.
Apart from a loud penalty claim when Yorke tumbled under Winterburn's challenge, and Cole fired wide from long distance after James was forced to head clear from Michael Carrick's underhit backpass, Blackburn didn't look capable of going ahead for a second time.
Hammers should have gone in front on 73 minutes, but Bowyer hit his shot straight at Friedel after good build-up play from Di Canio and Cole, who was increasingly looking to move inside from the left wing, where he was too often starved of good service.
Six minutes later Cole broke up play and set Di Canio clear down the left but Paolo's left-foot strike cannoned off the legs of Friedel.
With seven minutes remaining, Roeder made the decisive substitution. Bowyer, who fought well but misplaced too many passes, made way for Defoe, who had come off the bench to snatch the equaliser at Ewood Park in December's corresponding away fixture.
Rovers didn't heed the warning, though, and when Cole drilled a diagonal pass to the left edge of the box in the dying seconds, the England under-21 striker controlled it with his chest, cut inside onto his right foot and lashed a low shot inside Friedel's near post.
Sinclair, on for the leg-weary Di Canio two minutes from time, then saw a shot deflected wide following a Lomas cross as Hammers surged forward, roared on by a rampant crowd.
And this time, the defence held firm, with no late scares. Having finally achieved their first home win in the Premiership, Hammers must now go into Sunday's Upton Park clash with Liverpool full of hope.
Minute-by-minute:
1 - An early chance for the Hammers, as Ferdinand is fouled 20 yards out, and Di Canio touches the free-kick to Carrick, whose shot is deflected into the arms of Friedel.
7 - McEveley booked for foul on Bowyer.
8 - Lomas' deep cross is met by Ferdinand, who heads straight at Friedel.
15 - Cole booked for foul on Gillespie.
21- Di Canio's corner is headed goalwards by Johnson, but cleared off the line by a Rovers defender. The ball is hooked back in by Bowyer and reaches Di Canio, whose fierce drive is superbly palmed away by Friedel. From the resulting corner, the ball is cleared and fired back by Bowyer, but Lomas pokes his effort just wide of the post.
30 - A hooked ball over the top of the Hammers defence causes chaos, as James needlessly rushes out and Andy Cole clips the ball over him. Johnson beats Yorke to the ball in the six-yard box and Bowyer then clears the loose ball for a corner.
38 - GOAL. After a sustained spell of pressure, Blackburn take the lead. Winterburn's desperate foul on Gillespie is punished as Thompson's free-kick isn't cleared and Yorke - criminally unmarked in the six-yard box - gratefully rams home the loose ball. West Ham United 0 Blackburn Rovers 1.
43 - Thompson's stinging effort from 20 yards out sails just over the bar.
Added time: 1 minute.
Half-time: West Ham United 0 Blackburn Rovers 1.
Second Half:
46 - Hammers make a lively start to the second half and go close twice in the space of a minute. First Ferdinand is blocked off as he turns inside the penalty area, then Di Canio's flighted pass reaches Bowyer, whose shot from the edge of the area is charged down.
51 - Carrick's pass is chested down by Johnson for Bowyer, whose first time snapshot flies well wide.
57 - Hammers are presented with a glorious chance to get back in the match, as Joe Cole's determination releases Di Canio, who cuts in from the left and is cynically chopped down by Todd just inside the area. Referee Wiley immediately points to the spot.
58 - GOAL! Di Canio holds his nerve to stroke the spot-kick high into the net. West Ham United 1 Blackburn Rovers 1.
58 - Substitution for West Ham, Kanoute replaces Ferdinand.
65 - After Carrick's short back-pass is headed clear by James, Andy Cole fires a fierce low shot just wide of the target from 25 yards out.
70 - Substitution for Blackburn, Johansson replaces Gillespie.
74 - Another opening goes begging for the Hammers, as Cole's pass is dummied by Kanoute and finds it's way through to Bowyer, who shoots straight at Friedel.
80 - Another glorious chance is wasted. Cole again fights to release Di Canio clean through on goal, but the Italian's left-footed shot is saved by the legs of Friedel.
84 - Substitution for Blackburn, Ostenstad replaces Yorke.
84 - Substitution for West Ham, Defoe replaces Bowyer.
86 - Di Canio's flick-on reaches Kanoute, who races into the box but fires high and wide.
88 - Substitution for West Ham, Sinclair replaces Di Canio.
90 - GOAL! Is this the ray of light that could save West Ham United's season? Cole's magnificent cross-field pass picks out Defoe, who chests in the box, turns on to his right foot, and fires in a blistering low shot that beats Friedel at his near post. West Ham United 2 Blackburn Rovers 1.
Added time: 1 minute.
Full-time: West Ham United 2 Blackburn Rovers 1.