Super League leaders St Helens scored three tries in the last 12 minutes to snatch victory over Castleford.
Second-placed Cas looked well on course for the nine-point win they needed to take over at the top when they led 24-6 at the break, centre Michael Shenton scoring twice against his former club.
But, on the night he broke the Super League appearance record, Paul Wellens scored after a Tommy Makinson special.
And winger Adam Swift completed the comeback three minutes from time.
Sia Soliola, Jonny Lomax and Jordan Turner scored Saints' other three tries on a night when the ageless Wellens sparked the remarkable fightback which enabled the leaders to maintain their 100% record.
Playing his 414th Super League game, the 34-year-old Saints legend overtook the record previously held by one of his former England and Great Britain team-mates, Leeds centre Keith Senior.
His appearance at the start of the second half proved the catalyst - and, when he ran in the fourth of Saints' five second-half tries, he brought up the 1,000th point of his career.
Saints could hardly have made a worse start, the returning Jon Wilkin knocking-on from the kick-off, to allow Cas to score their first try inside their first set of tackles.
Centre Jake Webster set the scoreboard rolling by taking Daryl Clark's short pass to go through the visitors' defence, Marc Sneyd kicking the first of his four goals.
Winger Justin Carney was denied by the video referee for a knock-on by Shenton before turning provider on 11 minutes when he collected Liam Finn's high kick to send his skipper over for the first of his two touchdowns.
A grubber kick from Sneyd then bounced awkwardly for Saints, creating a try for loose forward Grant Millington, Sneyd's third conversion making it 18-0. And it could have been more, but prop Craig Huby spilled the ball going over.
Two goal-line drop-outs and a big contribution from replacement Alex Walmsley gave St Helens the momentum to pull a try back on 27 minutes when second-rower Soliola took Wilkin's pass to power his way over.
Luke Walsh's goal made it 18-6 but the Tigers struck again nine minutes before half-time when Shenton scooped up a wayward pass from Turner to sprint 40 metres for his second try.
Cas left the field at half-time to a standing ovation but Wellens, unused throughout the first 40 minutes, led his team out for the start of the second half, and that turned the game.
The Tigers had a third try disallowed when full-back Luke Dorn was ruled to have benefitted from obstruction, and Saints struck with two tries in seven minutes.
Full-back Lomax took a return pass from centre Josh Jones to touch down wide out before right-winger Makinson, Super League's top try scorer, produced one of his now trademark flying finishes to touch down one-handed in the other corner - his ninth of the season.
Walsh had the misfortune to strike the woodwork attempting to convert both second-half tries to leave his side trailing by 10 points, and Castleford looked to have made sure of victory on 59 minutes when Carney won the race to Sneyd's kick to the corner.
However, Turner collected Wilkin's kick on 68 minutes to start the fightback, Wellens then finished off a thrilling cross-field move and Swift gathered Wilkin's pass to cross for the winner.
Castleford coach Daryl Powell:
"It's disappointing. It was new Cas in the first half, then old Cas in the second half. I thought the second half was very poor from us.
"We allowed a team that can play a fair bit of rugby league back into the game.
"There are some hard lessons to be learned. I thought we should have won the game. I'm not sure the video ref got all the decisions right, but I'm not going to blame anybody but us."
St Helens coach Nathan Brown on Paul Wellens:
"He's an amazing player and an amazing captain for us. It's no coincidence that when 'Wello' went on the field the commitment from each player was better.
"The boys have got a lot of respect for him and, as far as captains go, and I don't think there's any better around."
Castleford Tigers: Dorn; Clare, Shenton, Webster, Carney; Sneyd, Finn; Lynch, Clark, Huby, Hauraki, Holmes, Millington.
Replacements: Milner, Massey, Boyle, Mariano.
St Helens: Lomax; Makinson, Turner, Dawson, Swift; Wilkin, Walsh; Masoe, Roby, McCarthy-Scarsbrook, Soliola, Manu, Jones.
Replacements: Laffranchi, Wellens, Walmsley, Greenwood.
Referee: Ben Thaler