Wigan let an eight-point lead slip from their grasp as Jamie Ellis' late drop-goal settled a dramatic contest.
Shaun Wane's Warriors took a 12-4 advantage into half-time but dropped off as a gutsy Tigers effort saw them score 14 unanswered points and go 18-12 ahead.
Tom Davies' sizzling try - converted by Sam Tomkins - then locked the scores and set-up a nerve-shredding finish.
Both sides missed with two goal drop-goal attempts and Tomkins had a potentially match-winning try chalked off for obstruction before Ellis had the decisive, final, say.
The result denied them a chance to reel in St Helens' lead at the top of the table.
On a shortened pitch and with several penalties and breaks, the action quickly swung from end-to-end and while the match lacked quality, the seesawing scoreline and tense finish made it absorbing viewing.
On the positive side for Wigan, Romain Navarrete, Tony Clubb and Gabriel 'The Hammer' Hamlin providing much of the aggression up front, Liam Paisley had a strong debut and wingers Liam Marshall and Davies scored top-drawer tries.
But they faded in the second-half and will lament the chances they let slip from their grasp, particularly given how depleted their opposition were.
Castleford were missing 11 of their first-choice 17, and fielded eight props including five in their starting pack.
Wigan, though, had absences of their own with seven frontline players missing including John Bateman and Sean O'Loughlin, who are in the England side to face New Zealand in Denver, USA.
Those absences provided a chance for forward Paisley to start on debut, while halfback Josh Woods made his fourth appearance of the season in place of injured George Williams.
The Warriors won the meeting at the DW earlier this year and went into this knowing it was the proverbial four-pointer; victory would open up a five-point gap on Cas, with defeat cutting the margin to just a point.
They suffered an early blow when centre Dan Sarginson was helped off with a lower-leg injury. In the reshuffle, Willie Isa moved to centre - meaning debutant back-rower Paisley was the only back-rower on the pitch in a back-row spot!
Woods had trained on a shortened pitch in the build-up and one of his high-kicks - with the sun behind him - was spilled by James Clare, who was also on the receiving end of a bone-jarring shot by Navarrete moments later.
Cas favour their left-edge and Jy Hitchcox, who pillaged four tries last week, went close to opening the scoring in the 13th minute but fumbled the ball with the line beckoning.
Relieved, Wigan marched down field and Tomkins attacked the right side, weaving through the defence and lunging for the line to take a 4-0 lead.
Cas' spilled another kick, conceded two penalties in possession for play-the-ball offences and were pinged for holding down. Given the possession and territory which Wigan enjoyed, they really should have extended their lead but the closest they went was when Thomas Leuluai - on his 33rd birthday - was held up over the line.
And that came back to bite them in the 26th minute when Cas' attacked to the left and Quentin Laulu-Togaga'e - referred to as QLT for obvious reasons - ghosted through the line to lock the score. Sam Powell pleaded obstruction but James Child awarded the try.
The tempo appeared to drop, but Marshall brought it roaring back to life with a stunning solo try on the half-hour in which he pinballed through two defenders to break away from inside his own half, and then beat a stranded QLT. Tomkins' goal put Wigan 10-4 ahead.
Electric Frenchman Morgan Escare punted a loose ball and zipped away and, though Clare tracked him down, it put Wigan into position from which Tomkins struck a 37th minute penalty after another play-the-ball infringement to make it 12-4 at the break.
Isa was put on report early in the second-half after colliding with Hitchcox as he leapt to defuse a kick. The winger landed awkwardly and left the action. From the resulting penalty, Cas' marched down field and captain Michael Shenton crossed from an old school-style runaround. Ellis converted and minutes later hit a penalty to once again draw the scores level.
From the restart Clare pierced the line and jetted down field. Isa eventually dragged him down and then breathed a sigh of relief when James Green bombed what seemed a certain try from the next play.
Still, they remained on the back-foot, as Cas' hammered away at their line until it eventually splintered and Matt Cook trundled over to put the hosts ahead for the first time. Ellis' conversion made it 18-12.
Cook, though, blotted his copybook by getting sinbinned for a dangerous tackle on Navarrete and - seconds later - Wigan pounced to take advantage of the numerical advantage and again level the scoreline.
A sweet pass from Tomkins unleashed Tom Davies, who blazed down field and beat the covering defence to dive over for a try which the former converted.
Ellis missed with two drop-goal attempts, sandwiching Woods' wayward one-point effort, before Tomkins was denied a try. With less than a minute to go, Ellis made it third time lucky to settle the contest.
Castleford: Laula-Togaga'e; Clare, Webster, Shenton, Hitchcox; Ellis, Trueman; Cook, McShane, Massey, Moors, Millington, Maher. Subs: Springer, Green, Clark, Egodo.
Wigan: Tomkins; Davies, Sarginson, Gildart, Marshall; Woods, Powell; Navarrete, Leuluai, Flower, Paisley, Isa, Hamlin. Subs: Escare, Field, Clubb, Tautai.
Referee: James Child
Star man: Gabriel Hamlin