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)