Catalan Dragons moved to third in Super League and denied Huddersfield the chance to go back on top.
Dragons led at half-time with tries by Damien Cardace, Clint Greenshields and Leon Pryce to Luke Robinson and Dale Ferguson's converted scores.
Scott Grix's try put the visitors back in front after the break.
Giants centre Joe Wardle briefly levelled the score, after Remi Casty's try, before Thomas Bosc's drop-goal and Vincent Duport's late score sealed it.
The Dragons' victory puts them two points behind leaders Wigan with a game in hand, but their joy was tempered by the loss of scrum-half Scott Dureau with a knee injury.
Huddersfield had an early Luke George try ruled out for a forward pass, and it was the home side who finally took the lead when Dureau's high kick bounced awkwardly and presented Cardace with a gift.
Robinson got the Giants on the board when he sprinted in from 50 metres following a quickly-taken tap penalty, but was then brushed off by Greenshields as Catalans regained the lead.
Ferguson made the most of some weak defence to put Huddersfield back in front, with Danny Brough's conversion making it 12-8, but the Dragons were in front for the third time before the break when Cardace sent Pryce over.
Yet again the Giants hit back when Grix jinked his way over, and the lead changed hands once more when Casty forced his way over from close range, Thomas Bosc's conversion making it 20-16.
Wardle crossed eight minutes from time to tie the scores, but Catalans nicked it when Bosc's drop-goal was followed by Duport's decisive try.
VIEWS FROM THE DRESSING ROOM
Huddersfield coach Nathan Brown:
"Apart from a couple of players, I thought we weren't quite good enough to beat a good side today.
"Apart from Michael Lawrence and Dale Ferguson, I thought every other player in our team didn't produce a performance they needed to produce.
"It's been a long time since we lost so it's no good slitting our wrists.
"We're halfway through the year and no one is on more points than us and we're in the Challenge Cup quarter-finals so I can't be too hard on the guys. We'd have taken that at the start of the year."
Catalan Dragons: Greenshields, Cardace, Duport, Millard, Bosc, Pryce, Dureau, Baitieri, Menzies, Sa, Paea, Henderson, Casty.
Replacements: Fakir, Pelissier, Anderson, Simon.
Huddersfield: Eden, George, Cudjoe, Wardle, McGillvary, Grix, Brough, Brown, Chan, O'Donnell, Lawrence, Robinson, Crabtree.
Replacements: Faiumu, Ferguson, Patrick, Mason.
Referee: Richard Silverwood (Great Britain)