The win over an abject Hull FC coupled with Wakefield Trinity's home defeat to Catalans Dragons takes the Tigers four points clear of their relegation rivals with only two rounds remaining.
Given Wakefield have won only four games all year, it would take something miraculous to keep Mark Applegarth's side in the top flight.
A tense relegation battle appeared to have swung back Trinity's way following Castleford's 66-12 defeat at Warrington Wolves but Danny Ward's men delivered the perfect response at the perfect time in their final home match of the season.
Usually so strong at Wheldon Road, 10 home defeats tells the tale of a miserable campaign.
But all that was forgotten momentarily as the home fans belted out 'Sweet Caroline' to toast a victory that lifts the gloom that has hung over the old stadium in 2023.
A review into the club's failings will come later but for now, the Tigers can breathe a huge sigh of relief.
Their senior men led from the front on a sweltering night in West Yorkshire, Joe Westerman and Liam Watts setting the standard in the pack and Gareth Widdop enjoying a 300th career game to remember.
Jason Qareqare marked his first appearance since June with a double, while there were tries for Alex Foster and Jordan Turner in their final outings at the Jungle.
A frenetic contest showed how much work Hull have in front of them in the off-season as they slumped to a fifth defeat in six games in a familiar late-season collapse.
It had the feel of a wild night from the very start.
Hull laid down an early marker with two forceful gang tackles to drive Castleford ball carriers back towards their own line but Joe Cator took the aggression too far with a high tackle that sparked a brief melee.
From the penalty, Castleford rolled downfield and broke the deadlock inside three minutes when Qareqare danced around the hesitant Davy Litten to finish in the corner after being put into space by Widdop, who added the touchline conversion to make it the perfect start for the hosts.
Backed by a fervent crowd, the momentum was with the Tigers but instead of riding on the back of the energy created by the fans, the hosts went into their shells.
An error by Elliot Wallis close to his own line sparked an argument with Westerman and it felt like the tide was turning when Adam Swift raced over in the corner thanks to fast hands from Tex Hoy.
Darnell McIntosh kicked his first goal of the year from the touchline to bring Hull level after 12 minutes but their half quickly descended into farce.
Swift's try could not paper over the cracks of a clunky performance in the absence of recognised half-backs.
Basic errors invited Castleford back in and they went close to restoring their lead when Greg Eden claimed a high kick only to throw a forward pass to Jack Broadbent with the tryline begging.
The mistakes kept coming with young full-back Litten in particular enduring a torrid night.
To his credit, he did not allow his head to drop and quickly redeemed himself for two unforced errors with a try-saving tackle on Eden when the stand-in half-back looked destined to score.
Hull appeared to have weathered the storm – relying more on luck than judgement – and had the chance to issue a response following another mistake by Wallis, this time from a high kick.
But in the blink of an eye, Castleford were at the other end celebrating Qareqare's second try after the young winger read Hoy's telegraphed looping pass to go 80 metres.
Widdop added the extras from in front – and it soon got better for the Tigers.
With 32 minutes on the clock, Blake Austin rolled a grubber kick into the in-goal area that was not dealt with by Hull and Eden pounced to finish.
Widdop knocked over another straightforward conversion to make it 18-6, which had the look of a decisive lead on the evidence of a scrappy first half.
McIntosh had a try ruled out for a forward pass just before half-time to sum up Hull's struggles in the opening 40 minutes.
The interval gave everybody inside the Jungle an opportunity to catch their breath and there wasn't quite the same frenzied feel when the players returned.
An uneventful start to the second half suited the hosts down to the ground as they protected a precious lead.
Castleford demonstrated their desperation with two try-saving tackles to end the threat of a Hull comeback, the highlight a last-ditch effort by Wallis to deny Swift.
After absorbing the best the Black and Whites could throw at them, the Tigers went in search of a killer fourth try.
Qareqare looked like the man to provide it, only to be denied by a Litten high tackle that earned the youngster a spell in the sin bin.
A frantic game threatened to take another twist when Widdop missed the penalty from out wide and then fumbled the drop-out on his own 20.
But another poor pass by Hoy ended the threat and Castleford steadied themselves to move out of sight.
Austin settled the nerves with a cool drop goal before Foster finished Eden's kick to spark jubilant scenes in front of the Wheldon Road End.
Swift went over out wide to give Hull's large travelling contingent something to cheer about but the night finished how it had started.
Widdop dabbed a kick into the in-goal area and Turner was on hand to touch down to crown a night to remember for the Tigers at the end of a forgettable season.
Castleford Tigers: Widdop, Qareqare, Turner, Broadbent, Wallis, Eden, Austin, Watts, Johnstone, Mustapha, Edwards, Mellor, Westerman. Substitutes: Griffin, Massey, Robb, Foster.
Hull FC: Litten, Swift, Scott, Tuimavave, McIntosh, Lovodua, Hoy, Fash, Houghton, Taylor, Lane, Savelio, Cator. Substitutes: Satae, Brown, Staveley, Dwyer.
Referee: Ben Thaler.