Two goals in five minutes from Christian Benteke and Charles N'Zogbia gave Villa an overdue home win which lifted them out of the Barclays Premier League relegation zone.
It was only the third league home success of the season for Paul Lambert's side but these three points could ultimately be crucial in the battle for top-flight survival.
Benteke calmly slotted home his 15th goal of the season with a 74th-minute penalty after N'Zogbia had been pulled down.
And the French midfielder added number two with a superbly-executed free-kick before Ashley Westwood's late own-goal made for an uncomfortable finale.
Yet Villa could have been on their way to victory as early as the second minute, and Andi Weimann will have nightmares over the miss which left the scoresheet blank when home supporters should really have been celebrating an early lead.
Benteke cut in from the left to hit a skidding low right-foot drive which Jussi Jaaskelainen fumbled as he fell.
With the keeper grounded and the goal at his mercy, Weimann was a touch too meticulous as he aimed for the far corner and saw his shot roll beyond the far post.
The Austrian was then halted by James Tomkins' timely sliding tackle as he raced through the middle after Benteke had headed on Nathan Baker's lofted pass.
In the 11th minute Baker and Andy Carroll both needed treatment after a clash of heads as they contested a corner in the visitors' goalmouth, while Benteke was unable to keep his header down following a Westwood free-kick from the right.
Half an hour had passed before the Hammers produced their first attempt, Mohamed Diame sending an angled drive well wide, and a minute later Brad Guzan comfortably held a Carroll header.
The keeper was relieved, though, when Ciaran Clark's sliding interception diverted a menacing cross from sub Guy Demel into his arms.
Five minutes before half-time, Ron Vlaar was close to his first goal for the club, the skipper finding space at the near post to meet Westwood's right-wing corner with a shot which bounced down into the turf before going just over.
West Ham were more forceful at the start of the second half, Tomkins having an angled shot blocked before Jordan Bowery headed a dangerous cross over his own bar.
Then Clark made three important clearances in quick succession as the visitors sought to capitalise on their best spell so far.
Matt Lowton also did well to block a Kevin Nolan effort before Villa made a double substitution, sending on Darren Bent and new boy Simon Dawkins for Bowery and Weimann respectively.
The switches gave the home side an immediate boost, N'Zogbia sending a fierce left-footer only just beyond the far post after Benteke had created the opening with a fine run and pass.
If Bent had been brought on to add power up front, his first task was to clear Carroll's 66th-minute shot off the line.
But in the 74th minute he was involved in the move that led to the opening goal, playing the ball to Benteke, who switched the ball inside to N'Zogbia.
The French midfielder was tripped by Mark Noble, and Benteke calmly slotted the resultant spot kick into Jaaskelainen's left-hand corner as the keeper dived the other way.
Five minutes late it was 2-0.
Bent was brought down by Tomkins just outside the area, and N'Zogbia's left-foot free-kick was sheer perfection, his shot lifting over the Hammers' defensive wall and beyond Jaaskelainen's reach.
That prompted a West Ham revival in which a Pogatetz shot was deflected for a corner by Westwood and Ricardo Vaz Te's far past header was clawed away by Guzan.
And when Joe Cole's speculative cross looped off Westwood's head and into the far corner for an 87th-minute own goal, it was suddenly backs-to-the-wall for the home side, Guzan making excellent stoppage-time saves from Kevin Nolan and Carlton Cole before the final whistle brought huge roars of delight and relief.
Villa: Guzan; Lowton, Vlaar, Clark, Baker; Westwood, Delph; Bowery (Bent 64), N'Zogbia (Sylla 85), Weimann (Dawkins 64); Benteke. Unused subs: Given, Holman, Bannan, Bennett.
West Ham: Jaaskelainen; Reid, Tomkins, Pogatetz, Taylor (Vaz Te 68); O'Brien (Demel 24), Nolan, Diame, Noble (C Cole 76); J Cole; Carroll. Unused subs: Spiegel, Jarvis, Chamakh, O'Neil.