Everton staged a dramatic fightback to finally ensure their Premier League survival with a game to spare on an incredible night at Goodison Park.
It looked bleak for Frank Lampard's team when they trailed 2-0 at the break but they dug deep in their hour of need and second half goals from Michael Keane, Richarlison and Dominc Calvert-Lewin secured the three points they so desperately needed.
They were facing a trip to the Emirates needing a result against Champions League-chasing Arsenal but now they can relax on Sunday having taken their points tally to 39 - one more than Leeds and Burnley can get even if they manage to beat Brentford and Newcastle respectively.
Calvert-Lewin's 85th minute diving header winner sparked wild scenes of celebration and a pitch invasion by some fans but when the pitch was finally cleared Everton managed to see out a tense finale before the party started.
Dele Alli has made little impact since signing in January but his introduction as a half-time substitute sparked Everton's improvement.
If anyone thought that Palace might be easy prey and had nothing tangible to play for they were mistaken.
Patrick Vieira's knew that a win would move them up to 11th, give them a chance of a top 10 finish by beating Manchester United on the final day, and put the gloss on an upbeat campaign under the former Arsenal and France midfielder.
They the better team in the first half but were helped by two poor goals from Everton's point of view.
Richarlison had gone desperately close to giving Everton the early lead they craved when his 25 yard free-kick clipped the top of the bar but it was Palace who took the lead by exposing the home side's vulnerability from set-pieces.
Eberechi Eze swung over a free-kick which eluded a bunch of players but found Jean-Philippe Mateta running in unchallenged and he scored with a downward header. Several water bottles were aimed in the direction of the Palace players as they celebrated in front of the Glwadys Street end.
Anthony Gordon was clearly being targeted by Palace. Will Hughes was booked for a heavy challenge from behind on the Everton player and the game boiled over when Ayew launched into a dangerous 'scissors' tackle on Gordon right in front of the technical area. He was lucky to escape with only a caution, much to the home crowd's fury.
To add insult to injury, Ayew then put Palace 2-0 up with a goal that Everton will have nightmares about.
Seamus Coleman lost possession on the half-way line to Mateta who drove forward. His cross was only half cleared by Jordan Pickford, who was impeded by Vitali Mykolenko, as he raced off his line. Wilfried Zaha fired the loose back into the six-yard box where Ayew diverted the ball over the line with his chest despite the desperate efforts of Mykolenko and Abdoulaye Doucoure to clear it off the line.
It was a nightmare scenario for Everton but Lampard reacted to the desperate situation by sending on Dele Alli, despite the former Tottenham and England player having had little impact since joining the club in the January transfer window.
It sparked a much-needed improvement with Everton knocking the ball around with more confidence. And they pulled a goal back after 54 minutes thanks to a combination of three members of their defence. Mykolenkpo sent over a free-kick, Mason Holgate headed it down and Keane took of a touch before finishing with all the assurance of a striker.
Lampard then sent on Demarai Gray for Gordon in a bid to snatch the equaliser but Palace were always a threat on the break and Pickford - so often Everton's saviour in recent weeks - made a fine save from a shot by Mateta as he threatened to restore his side's two-goal lead.
Richarlison has also been a real talisman for Everton in recent weeks and he lifted the roof off Goodison Park with his equaliser in the minute. Alli's cross bounced off Joachim Anderson and Richarlison seized the moment by sliding a a shot into the far corner of the net from a tight angle.
That was nothing to the explosion of nose when Calvert-Lewin, who has endured such an injury-plagued season, sparked wild scenes of celebration when he scored with a diving header from Gray's cross.
After nearly seven minutes of added time the final whistle sparked a mass pitch invasion and wild celebrations that probably wouldn't be matched had they actually won some silverware.
Pickford 6; Coleman 6, Keane 6, Holgate 6; Iwobi 6, Doucoure 6, Gomes 5 (Alli 46, 8), Mykolenko 6; Gordon 7 (Gray 61, 7), Calvert-Lewin 7, Richarlison 8.
Begovic,Kenny, Allan, Godfrey, Davies, Van De Beek, Welch.
Butland 6; Clyne 6, Andersen 6, Guehi 6, Mitchell 6; Eze 8, Hughes 6 Milivojevic 56, 5), Schulpp 6 (Gallagher 73, 6); Ayew 6, Mateta 7 (Benteke 80, 5), Zaha 6.
Guaita, Ward, Kouyate, Edouard, Kelly, Rak-Sakyi.