Teddy Sheringham hit a spectacular strike five minutes from time to end another fight-back from Neil Warnock's battling Sheffield United side.
Marlon Harewood opened the scoring with a spectacular goal early in the game before Alan Quinn struck a stunning free-kick from 30 yards to level for the home side, but 38-year-old Sheringham had the final word.
West Ham, who shared in a thrilling 3-3 draw at Bramall Lane in January should have snatched the lead after just three minutes with United exposed on the left flank.
Midfielder Matthew Etherington raced to the byline and picked out the unmarked Marlon Harewood with a deep cross, but from six yards the big striker mis-kicked.
Harewood made amends six minutes later in terrific fashion after Blades full-back Alan Wright headed straight to his feet. The 25-year-old former Nottingham Forest frontman drilled an unstoppable shot from 25 yards beyond Paddy Kenny and into the top right hand corner for his third of the season.
Sheringham could have added a second after 20 minutes as he cleverly controlled a long pass downfield but finished casually, with his right-foot volley directed straight at the waiting Kenny.
West Ham, in total control, squandered another opportunity with the home back four in shreds. The lively Harewood outpaced Blades skipper Chris Morgan on the left flank before cutting inside but, with Sheringham waiting unmarked, he stabbed the ball straight at Kenny as he guarded the post.
Outclassed Sheffield had to wait until the 34th minute for their first real chance after winning a free-kick 20 yards out. Ashley Ward and Nigel Reo-Coker were booked following a scuffle and Jon Harley curled the ball inches wide of the far post.
Former Sheffield Wednesday defender Leigh Bromby foiled England Under-21 international Etherington minutes before the interval, blocking his strike from 18 yards.
Etherington was through in the 57th minute but took his shot too early, a low effort from the edge of the area, gratefully scooped up Kenny.
Quinn struck with a free-kick in the 66th minute after Paul Thirlwell had been upended by substitute Adam Nowland.
However, there was still time for Sheringham to hit the winner in the 85th minute - his free-kick from 25 yards taking a deflection to leave Kenny flat footed.