St Helens captain Paul Wellens sparked a remarkable fightback on his record-breaking Super League appearance to help the leaders maintain their 100 per cent record.
Castleford Tigers were heading for the top of the table when they led 28-14 after an hour but Saints, who fought back from 16-8 down at Huddersfield Giants last Sunday to win their Challenge Cup-tie, ran in three tries in the last 13 minutes to snatch a 30-28 victory.
Wellens, whose appearance at the start of the second half was the catalyst for the amazing comeback, was among the scorers on his 414th Super League appearance, bringing up the 1,000th point of his career in the process.
Saints could hardly have made a worse start, with the returning Jon Wilkin knocking-on from the kick-off, and Castleford scoring 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 unopposed and Marc Sneyd kicked the first of his four goals.
The Tigers' varied kicking game caused all sorts of problems for Nathan Brown's men.
Winger Justin Carney, hoping to celebrate his new five-year contract with a try, was denied by the video referee for a knock-on by centre Michael Shenton but turned 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 and created a try for loose forward Grant Millington and Sneyd's third conversion made it 18-0.
It ought to have been more, for prop Craig Huby lost the ball going over the line and Saints gradually clawed their way into the game.
Two goal-line drop-outs and a big contribution from substitute Alex Walmsley gave St Helens the momentum and they pulled a try back on 27 minutes when second rower Sia Soliola took Wilkin's pass to power his way over the line.
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 Jordan Turner to sprint 40 metres for his second try.
Castleford 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 benefited from obstruction and Saints struck immediately with two tries in seven minutes to give them hope.
Full-back Jonny Lomax took a return pass from centre Josh Jones to touch down wide out and right winger Tom Makinson produced a trademark flying finish in the other corner after the position had been created by an interception from left winger Adam Swift.
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 the win on 59 minutes when Carney won the race to Sneyd's kick to the corner.
However, Turner collected Wilkin's kick on 67 minutes to start the fightback, Wellens finished off a thrilling crossfield move for his 1,000th point and Swift gathered Wilkin's pass to cross for the winner four minutes from the end.