Huddersfield captain Danny Brough struck a late drop-goal to earn a third straight Super League win as Castleford suffered a third defeat of the season.
Cas were 12-0 up in 15 minutes through Michael Shenton and Justin Carney, but Joe Wardle and Leroy Cudjoe levelled.
Jermaine McGillvary put the Giants ahead and Kirk Dixon replied, before Scott Grix and Aaron Murphy went in.
Jake Webster and Daryl Clark dragged Cas back level before Brough's 75th-minute one-pointer stole victory.
Both sides came into the game in decent form but, after a tight opening, it was Castleford who hit the front with a quick-fire brace of tries.
Michael Shenton's fend and burst of pace took him over on the left, before Carney opened up the Giants defence with an unstoppable solo run from inside his own half.
Marc Sneyd converted both as the Tigers looked to be in control and could have been three tries up when Weller Hauraki was held up on the line.
The Giants finally found a response when Joe Wardle took a fizzing Brough flat pass and spun his way to the line.
The hosts then pulled level when Cudjoe made the most of Giants pressure to cross on the right, Brough landing his second conversion.
There was no let-up in the intensity in the second half as McGillvary marked his 100th Giants appearance with a score after an Oliver Holmes knock-on, but Castleford responded almost immediately when Dixon gathered a Sneyd chip kick to touch down in the corner.
Grix's dart from dummy-half sent the pendulum swinging back the home side's way and, after Brough launched a 40-20 kick downfield, the Giants scored another four-pointer when Murphy crossed on the left.
Daryl Powell's side showed their mettle with two tries as Webster showed great pace and skill to run in from halfway, and levelled when Clark grounded his own grubber.
Both sides committed errors as the tension rose but Brough stayed cool to clip over a drop-goal that settled it.
Huddersfield coach Paul Anderson told BBC Radio Leeds:
"Daryl Powell will tell you the same, both sides made some poor errors. I told the players at half-time if you look at the tale of the tape, we went set for set and then we broke.
"We were just dumb at times, but the real pleasing thing is that we've won a tight game at home. We're starting to find our feet but there is still room for improvement.
"We found a way to win against a good team and they asked a lot of questions."
Castleford coach Daryl Powell told BBC Radio Leeds:
"It's disappointing. We fought our way back into it and then had a gilt-edged opportunity to win the game but we didn't take it and Danny Brough's pretty good at the old one-pointers.
"There wasn't a lot in it. We were on top for large periods and they had their opportunities on the back of our errors and made a few errors as well, so they'll probably say the same thing.
"We made a few forced errors that gave Huddersfield the ascendancy but I'm proud of the boys for hanging in games."
Huddersfield: Grix; McGillvary, Cudjoe, Wardle, Murphy; Brough, Robinson; Crabtree, Lunt, Kopczak, Chan, Ta'ai, Lawrence.
Replacements: Bailey, Faiumu, Wood, Mullally.
Castleford: Clare; Dixon, Channing, Shenton, Carney; Sneyd, Ellis; Lynch, Clark, Huby, Holmes, Hauraki, Millington.
Replacements: Webster, Milner, Mariano, Wheeldon.
Referee: James Child (RFL).