Newcastle took a big step towards securing their Premier League status with a dramatic win against 10-man West Ham.
Issa Diop's own goal and a Joelinton tap-in had put the hosts in a commanding position at the break.
However, West Ham, who had Craig Dawson sent off for two first-half bookings, drew level from a Diop header and a Jesse Lingard penalty that was awarded after a VAR review.
But with the visitors seemingly on top, Newcastle had the final say, substitute Joe Willock heading an important winning goal that lifts Steve Bruce's side up to 15th in the table, with a nine-point cushion to the bottom three.
West Ham remain fourth but have now played a game more than fellow Champions League hopefuls Chelsea and Liverpool, who will have the opportunity to leapfrog the Hammers before they play again.
David Moyes' side had arrived in the north-east of England looking for a third consecutive win but were ultimately punished for a sluggish first half in which they conceded twice and had Dawson sent off.
Prior to his dismissal Dawson's heavy touch saw him clatter Joelinton, allowing the impressive Allan Saint-Maximin to race clear and fire in a shot that Hammers goalkeeper Lukasz Fabianski and defender Diop contrived to turn into their own goal.
Dawson, who had been booked earlier for a foul on Joelinton, received his second yellow card in the aftermath and was dismissed.
To compound matters Fabianski dropped a simple catch from a corner five minutes later to present Joelinton with a tap-in for Newcastle's second.
However, the visitors improved after the break and were unfortunate not to claim a share of the spoils in a thrilling finale.
Saint-Maximin inspires Newcastle
Steve Bruce has repeatedly claimed that Newcastle's season may have been on a different trajectory if he had been able to field Miguel Almiron, Saint-Maximin and Callum Wilson on a regular basis.
And while Wilson started on the bench against the Hammers, Almiron and Saint-Maximin were both excellent as the hosts took control of the contest.
Saint-Maximin in particular provided the thrust to Newcastle's early attacking play, beating opponents at will to create several excellent openings after cutting in from the left flank.
And it was entirely predictable that he would contribute as Newcastle made the breakthrough, accelerating away from Mark Noble, albeit benefiting from some calamitous play from Fabianski and Diop in the process.
Having just returned to full fitness Newcastle's biggest concern will be that the Frenchman hobbled off after 64 minutes.
In his absence they retreated further and further into their own half, handing West Ham the ascendancy before securing back-to-back league wins for only the second time this season.
Moyes influences Hammers show of character
In the build-up to this encounter Bruce had suggested that Moyes' accomplishments this season were worthy of the manager of the year award.
And when Lingard levelled matters after home defender Ciaran Clark had been penalised for a handball his claim appeared to be gaining yet more weight.
The Scot has set West Ham on course for their best Premier League finish ever and whatever he said at the interval clearly inspired a side that had toiled during the first period.
Making light of their numerical disadvantage, they displayed excellent character and on another day might have come away with an unlikely point.
Jarrod Bowen, Lingard and Vladimir Coufal all had good sights at goal before Diop headed in to give them further impetus.
And when on-loan Manchester United midfielder Lingard registered his seventh goal in as many games for the Hammers, it seemed as though there would be some reward for their second-half dominance.
Moyes will now hope they can carry that level of performance forward to next Saturday's potentially pivotal fixture against Chelsea in the race for a top-four spot.
'There always seems to be a drama' - what they said
Newcastle United 3-2 West Ham United: We are starting to show consistency - Steve Bruce
Newcastle manager Steve Bruce, speaking to BBC Sport: "I couldn't be more pleased with the way we played first half. We had threat, were dangerous every time, we got men forward.
"All of the stuff in the first half, we didn't do in the second. It is understandable, you go too deep and we made it comfortable for West Ham.
"I had seen the referee running over to have a look and I couldn't understand why. By all accounts it is a penalty. If it is we have to accept it. We tried to change instantly and put two strikers up the pitch. It has paid off.
"It was terrific from Saint-Maximin - it is important that he stays well. He has a badly swollen ankle. He is a very very good player."
On being safe? "I can't say that. With this club there is always a sting in the tail. There is no disputing it has been a difficult last few weeks but we have lost one of our last seven games and are starting to show that bit of consistency."
Newcastle 3-2 West Ham: Moyes 'sad' to see Hammers lose after fightback
West Ham manager David Moyes, speaking to BBC Sport: "It was costly mistakes that can happen in football. We weren't playing badly - a couple of big mistakes gave Newcastle a leg up. We showed great character in the second half, the sad part was the last 10 minutes.
"Maybe when it went 2-2 they had no choice but to come out and do something else. At 2-2 I was hoping we would be able to see it out. I thought we played well - we made individual mistakes, got a sending off. It wasn't because we played badly."
Newcastle reach goals landmark
Newcastle became the eighth side to hit the 800-goal milestone at home in the Premier League (801 goals).
West Ham lost for the first time in their 23 Premier League encounters with teams in the bottom half of the table since David Moyes returned to the club (W14 D8).
Newcastle enjoyed their fifth Premier League double over West Ham (also 1993-94, 1994-95, 2010-11 and 2017-18), something they've done as many times in the competition only against Spurs.
West Ham have scored four own-goals in the Premier League this season, more than any other side and the Hammers' joint-most ever in a single campaign in the competition (also four in 2000-01).
West Ham's Craig Dawson was sent off for the first time ever in his 345th appearance in English league football.
The two occasions in the Premier League this season to see a player score at both ends have come courtesy of West Ham - Issa Diop v Newcastle and Tomas Soucek v Arsenal in March.
West Ham's Jesse Lingard has posted his best-ever goal tally in a single Premier League season (nine goals in 10 games).
Joe Willock has scored three goals in nine Premier League appearances for Newcastle after netting just one in 40 for Arsenal.
- After the January 6 riot at the US Capitol Building, the mass media immediately seized the opportunity to call for more internet