Mark Viduka scored twice to help Newcastle to a win which was marred by another injury scare for Michael Owen.
Viduka (right) gets across Ferdinand to put Newcastle ahead
Viduka got in front of West Ham's Anton Ferdinand to head the Magpies ahead from Charles N'Zogbia's superb cross.
Dean Ashton volleyed the Hammers level following Lucas Neill's long throw but Viduka bundled in his second from close range after more good work by N'Zogbia.
Owen limped off with what looked like a recurrence of his groin problem before N'Zgobia tapped in the third.
Despite Viduka's double and N'Zogbia's man-of-the-match display the talking point of an open and entertaining game will once again be Owen's fitness.
The England striker, who hurt his groin in last Monday's defeat against Derby, was a surprise inclusion in the starting line-up. The problem reared up again soon after the break and he was once again forced off after 51 minutes.
Newcastle had settled any nerves they may have been feeling on the back of a depressing defeat against the struggling Rams within two minutes.
James Milner laid the ball back to N'Zogbia who whipped in a cross from the left flank and Viduka got in front of Ferdinand and crashed a near-post header past Robert Green and into the bottom of the net.
That goal should have provided the perfect platform for Newcastle but it was the Hammers, who adopted a more direct approach in the absence of the injured Craig Bellamy, who began to get on top.
Mark Noble was once again impressive in the heart of the Hammers midfield and a typical driving run almost bought an equaliser but Steve Harper tipped his fierce 20-yard strike away for a corner.
A slip by Claudio Cacapa then almost let Carlton Cole in and the warning signs were there for the home side.
And for a manager who built a reputation on being defensively organised and maximising set-pieces, Sam Allardyce will have been furious about the manner of West Ham's equaliser.
Neill hurled in a long throw which Ashton nodded up in the air and Cole showed excellent strength before flicking the ball on to Ashton who had continued his run and volleyed in from six yards.
Ashton celebrates after volleying the Hammers level
The home side responded, Viduka was denied by a fabulous defensive header by Ferdinand but within seconds the Australian restored the home lead.
N'Zogbia skipped his way down the left flank again and picked out Viduka and the burly frontman bundled the ball home from six yards.
The second half was less eventful although both sides pressed forward.
Owen's injury seemed to hand West Ham the impetus and they had a couple of half-chances.
First Ashton sent a flick header just wide of the far post and Steve Harper made a fabulous one-handed stop to deny Lee Bowyer a goal against his former club.
But Newcastle wrapped up the points with a quarter of an hour to go when Obafemi Martins picked out N'Zogbia and the young Frenchman tapped the ball in from close range.
Martins missed a glorious chance to add a fourth late on when he somehow shot wide after capitalising on a mistake by Matthew Upson and rounding Green.
Newcastle assistant manager Nigel Pearson:
"The most important thing was getting the result.
"At times we were a bit scrappy but we played well enough to win the game. Generally we're very, very pleased.
"The early goal was a huge help and I'm pleased for Mark Viduka and there's more to come. It takes time to settle but he looks like he is getting his confidence."
West Ham manager Alan Curbishley:
"You can't defend like we did and expect to get something from the game. You can't let in goals after two minutes - otherwise you don't give yourself a chance.
"We got back into it and were the stronger side in the first half but more poor defending at the end left us 2-1 down at half time.
"Overall I feel we've done enough to take something from the game. We played well to get back into it and it's desperately disappointing.
"Our attitude to defending, especially stopping the cross, was poor today."
Newcastle: Harper, Beye, Cacapa (Taylor 78), Rozehnal, N'Zogbia, Smith, Geremi, Butt, Milner, Owen (Martins 51), Viduka (Jose Enrique 73).
Subs Not Used: Given, Faye.
Goals: Viduka 2, 41, N'Zogbia 76.
West Ham: Green, Neill, Upson, Ferdinand, McCartney, Bowyer, Noble, Mullins (Ljungberg 62), Etherington (Spector 80), Cole (Camara 68), Ashton.
Subs Not Used: Wright, Collins.
Booked: Mullins, Cole, Bowyer.
Goals: Ashton 32.
Ref: Mike Riley (Yorkshire).