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)

Plymouth striker Oseni shocked by Nigeria call-up
African athletes possess NFL traits in abundance — Umenyiora
AFCON 2027: Udeze warns Chelle not to underestimate opponents
Joshua, Fury in contract stalemate
Agunbiade emerges Nigeria’s lone survivor at WTT Lagos
Nigeria call-up boosted my confidence – Alebiosu
First Eagles invite thrills Rangers’ Oputa
270 athletes begin journey to stardom in Edo
Itauma unfazed by Usyk threat
Arsenal win English Premier League after Man City draw at Bournemouth
AFCON qualifiers: Nigeria face Madagascar, Tanzania, G’Bissau
FIFA WORLD CUP 2026: Dreaming of Olise, Musiala, Eze, Saka - Priceless Jewels Nigeria Lost to Treachery
Rangers International going, going . . . (63,794 views)
Amaju Pinnick: A cat with nine lives (55,115 views)
Second Term: Amaju Pinnick, Other NFF Heavyweights Home to Roost •How Pinnick Broke the Jinx (53,072 views)
Current issues in Nigerian sports: Matters arising (52,636 views)
Sports Development: Zenith Bank on the zenith (52,551 views)
Missing $150,000 IAAF Grant: Solomon Dalung’s Hide and Seek game (52,455 views)
Gov. Abdullahi Ganduje’s solid footprints, commitment to sports development in Kano State (52,288 views)
NFF Presidency: Pinnick, Maigari, Ogunjobi, Okoye in Battle for Supremacy (51,849 views)
Olopade, BET9A wave of revolution in NNL (51,036 views)
Commonwealth Games 2018: Shame of Muhammadu Buhari, Solomon Dalung (49,533 views)
Ibrahimovic’s Man U exit: Whose decision is it? And in whose interest? (47,962 views)
John Mikel Obi: Segun Odegbami’s Outrageous Call! (47,406 views)