Huddersfield winger Luke George grabbed a hat-trick as St Helens were condemned to a third straight game without a win.
After George's early try, Saints hit back to lead 12-4 at the break thanks to tries from half-backs Lee Gaskell and Jonny Lomax.
But two more George tries after the break for a second treble of the season put the Giants in charge, Danny Brough adding an ultimately vital drop-goal.
Ade Gardner then crossed, but Lomax missed the kick and the Giants hung on.
After needing a last-ditch Jamie Foster penalty to salvage a draw in a 36-36 thriller against Hull KR at Craven Park a fortnight ago, Saints were on the wrong end of a dramatic finale themselves when Catalan Dragons scored after the hooter to win 34-32 at Langtree Park last Friday night.
But losing influential hooker James Roby with a knee injury exacerbated a worrying three matches without a win for last year's Super League runners-up.
“James Roby has a leg muscle injury which seems pretty nasty. It doesn't look good”
Royce SimmonsSt Helens coach
Roby, generally thought to be indestructible, fell into a heap following a 27th-minute tackle from Huddersfield winger Jermaine McGillvary and, although bravely attempting to play on, was forced to hobble off.
George's third try, a 90-metre spectacular created by man of the match Brough, was the highlight of a dramatic second half in which both teams had chances.
St Helens were shaken by the early enthusiasm of their hosts, who took the lead in the 16th minute when George took Luke Robinson's pass to finish decisively in the corner.
But Gaskell brought the visitors level in the 28th minute, jinking his way through, Lomax's conversion edging them ahead for the first time.
The game was still finely balanced when Huddersfield centre Leroy Cudjoe misjudged the pace of Lomax's grubber kick on the last tackle. And, after believing the ball was going dead, he watched in agony when the Saints scrum-half dived on it to score.
Lomax's second goal established an eight-point lead but it was down to just two five minutes into the second half when Kevin Brown and Michael Lawrence combined to get George over for his second try, Brough landing the touchline conversion.
Brough missed a chance to level midway through the second half when he kicked a penalty wide but he more than made amends when he set up what proved to be the match-winning try.
The scrum-half collected Gaskell's kick five metres from his own line and bemused the back-pedalling Saints defence on a glorious 50-metre run before finding Scott Grix, who sent George over for his third try.
Brough's conversion was this time successful after the ball amazingly rebounded off both uprights as well as the crossbar and, as if to emphasise, he could do little wrong, he extended his side's lead to five points with a drop goal.
That was to prove decisive when Gardner squeezed over at the corner, only for stand-in kicker Lomax's conversion attempt to drift well wide ensuring that the Giants' fourth win from five games took them to within a point of leaders Warrington.
VIEW FROM THE DRESSING ROOM
Huddersfield assistant coach Paul Anderson:
"It was a real good game, one you would expect from two teams who are going to be competing at the top end of the table come the end of the season.
"Danny Brough came up with some good plays but I can't give both teams enough credit because everybody contributed to the spectacle.
"We've played three of the top four teams and we're reasonably happy with how we're travelling but we're well aware there is a lot of room for improvement. It was by no means perfect but we showed a lot of grit and determination and a lot of desire to work for each other."
St Helens coach Royce Simmons:
"We worked really hard on our defence this week and I thought we defended very well for long periods of the game.
"The penalty count was 9-2 so we had to and that probably affected our attacking game which has been tremendous all year.
"We're getting the least number of penalties awarded to us so it's something we're doing a little bit wrong and we're going to have to fix it up."
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.