It looked as though honours would end even but Ayew produced an incredible moment of skill to complete the turnaround after West Ham had taken the lead.
Injury-hit Palace had failed to win any of their three games leading up to the busy Christmas programme, and when they fell behind in the 57th minute to Robert Snodgrass's clinical finish it appeared their poor run would continue.
But Roy Hodgson's side produced a spirited response and former West Ham midfielder Cheikhou Kouyate levelled.
That set up a frantic finale with Snodgrass going close before Ayew's stunning winner. Cutting in from the right, he produced a high-speed pirouette, then jinked between two bemused West Ham players before calmly dinking a finish over keeper Roberto, recalled after being dropped a month ago.
Had Lionel Messi or Cristiano Ronaldo scored the goal it would have been replayed endlessly, but Ayew was modest about an effort he described as "one of his best".
"When I had the ball I wanted to try and shoot with my left foot, I pushed it too far and tried to do everything on instinct," he told Amazon. "This victory is for the supporters."
Manager Hodgson was happy to big up his striker in a team performance he said went beyond the call of duty.
"It was a fantastic effort. The second goal was one of those wonderful individual efforts that will live long in the memory, get lots of airings on TV," he said.
West Ham had enjoyed a 12-day break since their last game was postponed because of Liverpool's World Club Cup commitments.
Yet they were sluggish in a dull first half in which Ayew wasted the best chance when he scuffed wide from close range.
Things livened up after the break on a damp afternoon and Ayew had another chance when he burst clear on the right but could not beat Roberto from a tight angle.
West Ham's opener came out of the blue.
Michail Antonio's clever pass released Snodgrass and he took a touch before curling past Vicente Guaita.
It sparked Palace into a greater effort and Ayew was again involved as they got level, nodding down James McCarthy's cross into the path of Kouyate who volleyed past Roberto.
Either side could have taken the win with Snodgrass denied by a brilliant last-ditch tackle by substitute Jaïro Riedewald before Ayew's late Christmas present for the home fans.
While Palace moved into the top half, West Ham remain hovering just above the bottom three after a ninth defeat of the season and the pressure remains on manager Manuel Pellegrini.
"It was a tight game, unfortunately for us we didn't keep that score because we dropped inside our box and allowed them to have possession," he said. (Reuters)

Urhobo College wins 2025 Principals’ Cup
Olusosun made me who I am — Osimhen
Elegbeleye eyes more NPFL partnerships
Nnadozie gets FIFA Best Award nomination
Marinakis on trial in Athens over inciting gang violence
Osimhen scores hat-trick as Galatasary sink Ajax
Eighty-five changes in 16 games - is Chelsea system working after draw?
Yamal scores stunning goal as Barca draw thriller with Club Brugge
GroupE THOP appoints three Distinguished Non-executive Directors to strengthen Governance and strategic ambition
Super Eagles Camp Opens Nov. 10 in Rabat Ahead of 2026 World Cup Playoffs
Real Madrid, Super League seek over $4bn in damages from UEFA
Rangers International going, going . . . (63,299 views)
Amaju Pinnick: A cat with nine lives (54,508 views)
Second Term: Amaju Pinnick, Other NFF Heavyweights Home to Roost •How Pinnick Broke the Jinx (52,458 views)
Current issues in Nigerian sports: Matters arising (52,088 views)
Sports Development: Zenith Bank on the zenith (52,080 views)
Missing $150,000 IAAF Grant: Solomon Dalung’s Hide and Seek game (52,012 views)
Gov. Abdullahi Ganduje’s solid footprints, commitment to sports development in Kano State (51,846 views)
NFF Presidency: Pinnick, Maigari, Ogunjobi, Okoye in Battle for Supremacy (51,427 views)
Olopade, BET9A wave of revolution in NNL (50,541 views)
Commonwealth Games 2018: Shame of Muhammadu Buhari, Solomon Dalung (49,106 views)
Ibrahimovic’s Man U exit: Whose decision is it? And in whose interest? (47,516 views)
John Mikel Obi: Segun Odegbami’s Outrageous Call! (46,994 views)