James Milner celebrates after scoring Aston Villa's winner
Aston Villa moved into third place in the Premier League after James Milner's deflected late goal sank West Ham.
An open first half saw Ashley Young hit the post for Villa after running on to a poor Scott Parker back-pass but West Ham dominated after the break.
Carlton Cole headed an easy chance over and was denied twice from close range by Villa goalkeeper Brad Friedel.
The visitors looked short of ideas until Milner's 78th-minute cross looped off Lucas Neill and into the net.
The goal was harsh on the Hammers, who had looked by far the most likely to break the deadlock but instead saw their miserable home form continue.
Villa, meanwhile, move above Manchester United and are now only four points behind leaders Liverpool, although they have played more games than all of their title rivals.
Martin O'Neill's men arrived at Upton Park having enjoyed the luxury of resting senior players in the midweek Uefa Cup defeat in Hamburg, their progress already sealed in that competition.
But, while the visitors may have been refreshed, it still took them time to get into the swing of things and it was the Hammers who began much the brighter.
Craig Bellamy had already seen one snap-shot saved by Friedel when he met Herita Ilunga's long ball and fired in an angled effort that the goalkeeper did brilliantly to push away.
Neill should also have done far better when Calum Davenport headed a Mark Noble free-kick into his path, swinging at the ball as it flew invitingly across the six-yard box and seeing his mis-hit volley fly wide.
An inability to find the net is the root of the Hammers' problems this season - they began the game just a point and a place above the relegation zone after scoring only four goals in their previous 10 league games.
And they were handed an early warning about their wastefulness here as Villa began to wake from their slumbers.
Villa's first chance saw Steve Sidwell fire just wide from Ashley Young's quickly-taken free-kick.
Sidwell missed the target again with another shot soon afterwards but only by a fraction after Gabriel Agbonlahor capitalised on a heavy touch by Neill and escaped down the left before sending in a low cross.
O'Neill praises Villa determination
Suddenly Gianfranco Zola's side were under pressure and they did not help their cause when Parker attempted to play the ball back to Green but instead only found Ashley Young, who rounded Rob Green but then hit the outside of the post.
The visitors also had a case for a penalty when Neill tangled with Gareth Barry as the ball flew over their heads inside the area and Green had to keep out shots by Milner and Barry before the break.
At that stage things looked ominous for West Ham but, strangely, Villa lost their way completely at the start of the second half.
Ashley Young and Agbonlahor, so prominent earlier on, disappeared from view and it was the Hammers who should have taken the lead when Cole met Neill's cross at the far post but failed to keep his header down with the goal gaping.
Only a last-ditch Luke Young tackle denied Cole again seconds later when he tried to meet Bellamy's cross at the near post but he still forced Friedel into a save after picking up the loose ball.
And Friedel was forced into yet another stop when Cole managed to find space to get his shot away from an even tighter angle in a similar position.
Defeat hard to take for Zola
Villa had barely threatened since the interval but they still collected all three points thanks to a massive stroke of luck.
Milner was trying to cross the ball from the left-hand side of the penalty area but instead it hit Neill and left Green helpless as it dropped under the crossbar and over the line.
West Ham manager Gianfranco Zola:
"It is very hard to take. I don't think my players deserved that and it makes me very frustrated.
"When my team plays well and creates chances like we did then I cannot complain - we need a change of luck but we will keep trying our best."
Aston Villa boss Martin O'Neill:
"I'm delighted to be third.
"We created quite a number of chances on the break in the first half but the game was really open and could have gone either way,"
"We got a bit lucky with the goal at a time when West Ham were pressing us."
West Ham: Green, Neill, Davenport, Upson, Ilunga, Collison (Tristan 84), Noble, Parker (Mullins 46), Behrami (Bowyer 57), Bellamy, Cole.
Subs Not Used: Lastuvka, Boa Morte, Faubert, Di Michele.
Booked: Neill, Bellamy.
Aston Villa: Friedel, Cuellar (Reo-Coker 58), Davies, Laursen, Luke Young, Petrov, Milner, Sidwell, Barry, Ashley Young, Agbonlahor.
Subs Not Used: Guzan, Harewood, Delfouneso, Knight, Shorey, Gardner.
Goals: Neill 78 og.
Ref: Mark Halsey (Lancashire).
BBC Sport Player Rater man of the match: Aston Villa's Ashley Young 7.80 (on 90 minutes).
Please note that you can still give the players marks out of 10 on BBC Sport's Player Rater after the match has finished.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.