Newcastle halted their alarming slide and ended West Ham's recent revival by edging a five-goal thriller 3-2 at the London Stadium.
Marko Arnautovic gave the Hammers, who had a spring in their step following recent wins over Chelsea and Stoke, a sixth-minute lead.
But the wheels fell off spectacularly as Newcastle raced ahead through goals from forgotten midfielder Henri Saivet, Mohamed Diame and Christian Atsu.
Andre Ayew, who had earlier missed a penalty, pulled one back but Newcastle held on for victory, their first win in 10 matches, to ensure they will not spend Christmas in the bottom three.