Maxwel Cornet struck five minutes from time to give Burnley a potentially vital 3-2 win over relegation rivals Everton in a frantic match which swung from end to end.
Burnley had taken an early lead through Republic of Ireland defender Nathan Collins' first goal for the club but then fell behind as Richarlison twice scored from the penalty spot before the break.
And the game swung again in the second half as Jay Rodriguez levelled in the 56th minute before Cornet's first goal since his return from the Africa Cup of Nations in January gave Burnley their first win in six games, moving them to within a point of Everton in 17th place.
A soaked and dejected Frank Lampard trudged off the pitch at full-time, his side now having lost six straight away from home in the league, sucked ever deeper into trouble.
Burnley had lost their last four without scoring a goal, being urged unceremoniously by Sean Dyche to simply "kick it in the goal", and the manager chose an attacking side as Rodriguez came in and Cornet replaced Dwight McNeil on the left.
Both managers had sought to downplay the idea of this as a relegation decider but there was a real sense of tension inside Turf Moor at kick-off.
Burnley were first to feed on that, with Charlie Taylor and Ashley Westwood both threatening before Collins broke the deadlock with 12 minutes gone.
It was another one for the defensive horror show reel at Everton. Cornet sent in a corner which floated over a crowd of Everton defenders for Collins to hook it back in for his first Burnley goal.
The goal was met with a huge roar from the home faithful, but within minutes they turned to groans.
Everton had barely made it out of their own half before Collins' strike, but when Anthony Gordon broke into the box he got on the wrong side of Westwood, who clumsily hauled him to the ground, and Richarlison's exaggerated, stuttering run-up did the trick as goalkeeper Nick Pope went the wrong way.
Everton were now on top. Richarlison's bending shot took a nick to bend just over after Abdoulaye Doucoure powered forward, then the Brazilian and Dominic Calvert-Lewin got in a muddle after Alex Iwobi's pass split the Burnley defence.
It was another Iwobi pass that released Vitaliy Mykolenko into the box and as the Ukrainian span away from Aaron Lennon he was caught by an out-stretched boot.
Referee Mike Dean initially looked away despite the Everton man's exaggerated response, but VAR Darren England sent the referee to the screens with the inevitable outcome of a second penalty. Again Richarlison sent Pope the wrong way.
Burnley drew level 11 minutes after the restart as Taylor cut in from the left and drilled a low cross through a crowd of Everton defenders for Rodriguez to hammer home from close range.
Everton sought an immediate response but Pope was alert to shovel to safety Richarlison's overhead kick before Calvert-Lewin headed over.
As rain swept over the ground, James Tarkowski made a vital block on Gordon's goal-bound shot with Jarrad Branthwaite, in for the suspended Michael Keane, heading over from the resulting corner.
Cornet then stumbled to the floor inside the box and turned to look at Dean, though the contact from Gordon had been soft.
Cornet was lively, getting back to defend but providing a constant threat. Ben Godfrey did well to turn away his low cross in front goal, then his curling shot was palmed over by Jordan Pickford.
But the Ivorian's efforts paid off with five minutes to go thanks to yet another defensive howler.
Godfrey got it all wrong trying to deal with Taylor's cross, and the ball spun for substitute Matej Vydra to drill a cross into Cornet's path, his strike sparking huge celebrations among the home faithful.
Watch St Patrick's Athletic v Dundalk live on RTÉ2 and RTÉ Player from 7.30pm on Friday with the latest scores from all other games on RTE.ie/Sport and RTE News app.
We need your consent to load this YouTube contentWe use YouTube to manage extra content that can set cookies on your device and collect data about your activity. Please review their details and accept them to load the content.Manage Preferences