Marko Arnautovic gave the Hammers the lead in the opening ten minutes before Henri Saivet equalised minutes later.
Mo Diame was on hand to give Newcastle the lead early in the second half, before Andre Ayew saw a penalty saved. The away side capitalised on that, as Christian Atsu added a third shortly after.
Ayew did make things interesting with around 20 minutes left, firing in to make things 2-3, but Newcastle were able to sustain late pressure to hold on for a vital three points.
Lively start in London
With just six minutes on the clock West Ham found themselves an early opener. Saivet, making his first start in the Premier League for Newcastle this season gifted the ball straight to Arnautovic and he took advantage.
The Austrian ran at the defender, before advancing into the penalty area and then firing beyond Rob Elliot to make it 1-0.
Four minutes later Saivet was having an impact at the right end of the pitch for his team, making up for his error by scoring a terrific equaliser. He lined up a free-kick 25 yards from goal, curled it over the wall and into the back of the net.
Wood work comes to Hammers rescue
The game was being played at an entertaining tempo and Newcastle had a brilliant chance to go ahead on 18 minutes. DeAndre Yedlin's cross from the right was met by Dwight Gayle but his effort struck the bar.
The wood work then denied The Magpies again later in the first half. Matt Ritchie cut inside and hit a curling effort which came back off the post, with the resulting follow put over the bar.
David Moyes' side continued to fashion chances for themselves and Antonio had perhaps their best chance to give them the lead with ten first half minutes remaining. Arnautovic's cross found Antonio unmarked but he put his header wide.
Newcastle add two either side of missed penalty
The second half started much in the same vein as the first half had and it wasn't long before Newcastle went in front for the first time in the game.
Atsu did brilliantly to get past his man and burst into the penalty area before squaring for Diame who was free to find the net and make it 2-1 to Newcastle.
However moments later West Ham were denied from the penalty spot. Antonio was brought down by Ciaran Clark right on the edge of the edge of the area, making it difficult to tell whether contact was actually made inside or outside the box.
Nonetheless Lee Mason pointed to the spot. Ayew stepped up but he saw his effort from twelve yards saved by Elliot.
It was a moment in the game that proved costly for the Hammers as the visitors scored a third five minutes later. Atsu led a fantastic counter attack down the middle of the pitch before playing in Joselu down the left. The Spaniard then played it back to Atsu who converted from close range.
Ayew gives Hammers a life line
With just over 20 minutes left Ayew made up for his penalty miss by breathing fresh life into West Ham's chances of getting something from the game.
Substitute Andy Carroll's header was kept out by Elliott but the rebound was followed up by Ayew who made it 2-3.
West Ham continued to press, but couldn't find an equaliser. Pedro Obiang fired over from the edge of the box, whilst Javier Hernandez's introduction to the game failed to spark any further opportunities.
The result meant Newcastle leap-frogged West Ham in the table as Rafa Benitez's men climbed to 15th in the Premier League.