Diafro Sakho scored a late winner to inflict defeat on new Sunderland head coach Dick Advocaat in his first match in charge and finally bring some cheer back to Upton Park.
The Hammers were in contention for the European places earlier in the season but have slipped down the Premier League with a terrible run of form in 2015.
It looked set to be another frustrating afternoon for manager Sam Allardyce, who is out of contract in the summer, before Sakho slotted home with just two minutes left to give West Ham a first league win since January 18, and leave Dutchman Advocaat in no doubt of the hard work ahead to secure Sunderland's top-flight status.
With former Hammer Jermain Defoe, Steven Fletcher and Connor Wickham leading the line, Sunderland began in positive mood and put West Ham under pressure.
They should have gone ahead on 14 minutes when Fletcher's flick-on put Defoe clear into the West Ham box. However, he ballooned a right-foot half-volley high into the stands.
Late in a scrappy second half, Sunderland defender Patrick Van Aanholt let fly from 25 yards with a rocket towards the top corner, and Adrian had to be alert to tip the ball behind as Advocaat held his head in his hands on the touchline.
It proved a pivotal save, as West Ham grabbed a winner with just two minutes left in the game. As Sunderland appealed for a foul on the edge of the penalty area, Mark Noble hooked the ball through to Sakho, who dispatched a cool, low finish into the bottom left corner.
Sunday Indo Sport