A remarkable comeback that included three tries in seven second half minutes brought Castleford Tigers a 38-28 victory over Wigan Warriors on a thrilling night at the Mend-A-Hose Jungle.
Daryl Powell's men looked to be heading for a fourth defeat in five games when their right side defence was in trouble again and they were trailing 20-0 after just 23 minutes.
But they began to dig in towards the end of the first half and maintained that progress with a strong second half show, led by bulldozing forwards Liam Watts and subs Matt Cook and Mitch Clark.
Cas started strongly and were unlucky not to take the lead in the second minute when great offloads by Grant Millington and Liam Watts gave Jake Trueman the chance to attack the line and he was tackled inches short.
Wigan showed their first threat when Dom Manfredi lost the ball trying to dive over in the corner, but they were back defending as Pater Mata'utia - playing at half-back - produced a good grubber kick that earned a drop-out with Zak Hardaker covering well.
The Tigers' struggles down their right hand side surfaced, however, when their first bit of defending failed as Joe Greenwood was allowed to get over the line despite the attentions of three home players.
To great cheers Hardaker's conversion attempt wide, but he was soon lining up a second kick - and missing again - after the Warriors attacked the Cas right again and Oliver Gildart swerved his way over after shrugging off an attempted tackle.
From the next set Wigan added their third try with Gildart breaking free of Tuoyo Egodo and Mata'utia in his own half and his subsequent break being backed up by George Williams for a score that was converted by Hardaker this time.
It got even worse for the hosts when despite a possible obstruction in the build-up Joe Burgess was sent over wide out. Hardaker's goal made it 20-0 after just 23 minutes.
Cas did at least begin to save face as they got some ball and started to use it with purpose on the back of some big bursts by Liam Watts in particular.
A Trueman grubber earned a goal-line drop-out and although the next set came to nothing the pressure was maintained for Oliver Holmes to score with a determined run.
Calum Turner was unable to add the goal, but the Tigers surged forward on their next set and it took some strong defence on their line for Wigan to keep out Jesse Sene-Lefao.
Another drop-out followed from a Trueman kick, but Wigan again showed the home team how to defend from the next set.
And when the Warriors were helped up field by a penalty they scored again with Gildart going over from acting-half, again benefiting from soft looking defending.
Cas did produce a better end to the half and after Egodo was halted just short on a strong run they scored when Turner came up with a great diagonal run onto Mata'utia's clever pass.
Turner was wide with the conversion attempt to leave the Tigers 24-8 down at the break.
Both sides forced drop-outs early in the second half before Cas got the message that they could overpower their opponents with some determined running down the middle.
They cut their deficit further when Clark marked his comeback game from injury by powering over from close range for a try converted by Mata'utia, who effectively took over the goal kicking job.
Two minutes later the Tigers were in again as Cook - on his 100th appearance for the Tigers - got the ball down over the line following a strong burst.
Mata'utia's goal cut the visitors' lead down to 24-20 and it was all Cas now.
Unbelievably they were ahead in the 53rd minute as Adam Milner burrowed over from acting-half for another try that was converted by Mata'utia.
With Trueman's kick forcing another drop-out the pressure was maintained, but Wigan held on and regained the lead on a rare second half attack when Williams' high kick was collected by Gildart and winger Burgess scooted over.
Hardaker was unable to goal, though, leaving just two points between the sides going into the last 10 minutes.
Wigan thought they were in again as another Williams high kick was juggled and Dom Manfredi touched down, but Dan Sarginson was deemed to have knocked on in the air by video referee James Child and the home fans breathed a sigh of relief.
The scene was set for a big finish and it was Tuoyo Egodo who emerged as the hero for the Tigers. The young centre had found it difficult in defence, but came up with a crucial try as he powered over from close range. Mata'utia added a superb touchline conversion and the hosts were back ahead at 32-28.
The icing on the cake was provided with the last play of the game as Wigan lost possession near their own line and Mata'utia pounced on the loose ball to score he try he converted.
Wins do not come much more remarkable than this.
Scorers - Castleford: Tries Holmes, Turner, Clark, Cook, Milner, Egodo, Mata'utia; goals Mata'utia 5. Wigan: Tries Greenwood, Gildart 2, Williams, Burgess 2: goals Hardaker 2..
Castleford Tigers; Turner; Clare, Egodo, Shenton, Eden; Mata'utia, Trueman; Watts, Milner, Millington. Holmes, Sene-Lefao, Massey. Subs: Cook, Clark, O'Neill, Maher.
Wigan Warriors: Hardaker; Manfredi, Sarginson, Gildart, Burgess; Williams, Sammut; Bullock, Leuluai, Navarrette, Isa, Greenwood, Partington. Subs: Byrne, Shorrocks, Smithies, Tautai.
Referee: Chris Kendall.