Eddie Howe's side trailed 3-1 after Alexander Isak's early penalty was erased by goals from Michail Antonio and Mohammed Kudus before half-time. When Jarrod Bowen scored West Ham's third immediately after the break, Newcastle looked set for another dispiriting defeat in a troubled campaign.
But Isak converted a second penalty to give the Magpies hope and Barnes came off the bench to equalise before snatching the winner in the 90th minute. Newcastle's Anthony Gordon was sent off for a second booking in stoppage-time, but the hosts clung on for a much-needed victory.
After coming under fire from frustrated fans during their recent swoon, Howe's relief was clear to see as he sprinted down the touchline in celebration of Barnes' second goal. Newcastle's Saudi owners would have expected their team to be much higher than their current mid-table berth after finishing in the top four last season.
But Newcastle's second win in their last seven games in all competitions, and the spirited revival that inspired it, offered hope that Easter might serve as a rebirth for Howe and his spluttering team.
Seventh-placed West Ham are just one point ahead of Newcastle after a result that will only lead to more criticism of boss David Moyes from the club's demanding fans.
Newcastle grabbed the lead in the sixth minute with a helping hand from West Ham defender Vladimir Coufal. Coufal's rash challenge on Anthony Gordon conceded a penalty that Isak fired past Alphonse Areola.
Already without players worth £250 million ($315 million) due to injuries or suspensions, Newcastle's injury-plagued skipper Jamaal Lascelles limped off in the 17th minute of his first league start since December.
Antonio took advantage of the uncertainty caused by Newcastle's
Read on besoccer.com