A drop goal from 40 metres out 55 seconds into extra-time sealed a Carnegie Challenge Cup quarter-final place for a relieved Castleford Tigers at The Jungle.
The game was decided by the golden-point rule and went the way of the Tigers after a titanic struggle with a Halifax side who were a credit to the National League.
The two sides had been locked together at 34-34 at the end of a thrilling 80 minutes of rugby league and Brent Sherwin's winning field goal was tough on gallant Halifax.
Castleford had led 16-12 at half-time but were made to work hard for their advantage and were behind until just before the half-hour mark.
Halifax showed all the confidence of a team who had been unbeaten in all games coming into this fifth round cup tie as they stormed into attack and scored first through Lee Paterson's fourth-minute penalty.
A 40-20 kick from Ben Black gave them good field position again and on nine minutes they scored the game's first try with centre Shad Royston diving onto a Black grubber kick over the line. Paterson's conversion made it 8-0.
Back came the Tigers and full-back Ryan McGoldrick shot through a gap to score under the post.
Kirk Dixon added the conversion but after Michael Shenton knocked on from the restart Halifax were awarded another penalty, which Paterson kicked to make it 10-6.
In an open game it was Castleford's turn to score next and they went in front for the first time as centre James Evans went over in the corner and Dixon added a touchline conversion on 28 minutes.
Halifax levelled through a third Paterson penalty only for the hosts to edge in front three minutes from half-time as Sherwin sent Shenton over in the left corner.
It was level again within two minutes of the second half as a superb handling movement resulted in Dwayne Barker going over on the left flank.
The stunned Tigers conceded again two minutes later as Bob Beswick darted over from close range. Paterson's goal made it 22-16.
But Castleford were back in front by the 54th minute as winger Dixon and stand-off Rangi Chase went over for unconverted tries.
McGoldrick was next to cross the line from close range and Dixon's conversion made it 30-22.
Back came Halifax to turn the game around with two tries by Beswick and two conversions from Paterson.
But Castleford levelled four minutes from time through Sherwin, who was unable to add the conversion.