Alex Iwobi's 99th-minute goal earned Everton a massive victory in their fight against relegation as they held on to beat Newcastle despite being reduced to 10 men.
An average game, which was delayed by a protestor tying himself to a goalpost by his neck, came to life late on when Allan was sent off with seven minutes remaining for taking out Newcastle substitute Allan Saint-Maximin.
Referee Craig Pawson consulted the pitchside monitor and overturned his initial decision to book the Everton midfielder.
At that stage, and with 14 minutes of stoppage time to play because of the protest, hanging on for a draw looked like the best Frank Lampard's side could achieve.
Yet in the ninth minute of additional time, substitute Dominic Calvert-Lewin led a breakaway and slipped Iwobi through before he found the bottom corner.
It led to wild celebrations at Goodison Park as Everton earned only their second win in 13 Premier League games to put three points between them and the relegation zone.
But, as Lampard and his players hugged each other in delight at the final whistle, it felt like a victory worth much more than that as they consigned Newcastle to a second consecutive defeat.
Everton overturn poor form with galvanising win
The last time these two teams played each other on 8 February, Newcastle were in the bottom three and four points behind Everton in Lampard's first league game in charge.
But victory at St James' Park and a golden period for Eddie Howe's side has propelled them to a point where it is Everton who are threatened with the drop.
This win, however, could act as a galvanising force for a team which has struggled for form and for most of this match showed themselves as a side bereft of confidence.
The fact the hosts were able to overturn what looked like a harsh decision on Allan will be all the more pleasing for Lampard and his team as they celebrated wildly with their fans as Pawson blew for full-time.
It was a pulsating end to an otherwise average encounter where Everton supporters had been reduced to cheering tackles and interceptions.
By contrast, Newcastle, with Joelinton back in the side, were a well-drilled unit and Bruno Guimaraes, making only his third start since joining the club in January, made them tick at the base of the midfield.
The visitors had the better of the first half as Chris Wood headed over and straight at Asmir Begovic, who started in goal in place of the ill Jordan Pickford.
And while Ben Godfrey had an early header saved by Martin Dubravka, Everton, who were also without Donny van de Beek, struggled to find any rhythm. Their half was summed up when the effervescent Anthony Gordon missed a kick on the edge of the area.
The second half took a bizarre twist when a protestor tied himself to a goalpost at the Gwladys Street End, which led to an eight-minute delay.
The protestor was later arrested on suspicion of pitch encroachment
But the break did not lead to an improvement as Demarai Gray shot wide and Guimaraes then mis-hit a shot which was saved before the game turned in Newcastle's favour with Allan was sent off just as his team were in the ascendancy.
Gordon had tested Dubravka with a curling effort, with Seamus Coleman appealing for a penalty shortly afterwards.
But as Newcastle broke away Allan took out Saint-Maximin, which led to a booking, which was soon overturned as Pawson was directed to the monitor by the video assistant referee Stuart Attwell.
That led to a feeling of acrimony inside Goodison, in tune with Everton's recent form.
The late reprieve and the host's ability to hold on as Newcastle pressed for an equaliser, turned the mood on its head, however.
Lampard will hope it can now lead to his team's Premier League survival.