|Wigan (6) 26|
|Tries: Gelling, Bateman, Smith, Sarginson Goals: Smith 4 Drop-goals: Smith 2|
|Huddersfield (12) 19|
|Tries: Brierley 3 Goals: Brough 3 Drop-goal: Brough|
Huddersfield full-back Ryan Brierley scored a stunning hat-trick of tries but Super League's bottom club lost to Wigan, who went top of the table.
Brierley, who signed from Championship side Leigh Centurions in March, had never crossed in the top flight before.
Wigan tries from Anthony Gelling, John Bateman and Matty Smith made it 18-18.
Smith and Danny Brough swapped drop-goals before Smith landed a second one-pointer and Dan Sarginson's score sent the Warriors to the summit.
Shaun Wane's Wigan moved two points clear of Warrington and Catalans, although for so long it appeared that the visitors would register two successive wins for the first time in 2016 and move off the foot of the table.
Brierley's hat-trick was high in quality - Leroy Cudjoe's break set up his first, while his second was created by Brough's superb grubber kick.
After Huddersfield had been pegged back to 12-12 by Bateman's close-range score, some free-flowing handling gave Brierley a free run to the line - a try scored while team-mate Nathan Mason was in the sin-bin.
The final 10 minutes became a drop-goal contest between half-backs Smith and Brough, and Wigan forged a crucial one-point lead before England international Sarginson raced over in the dying seconds to clinch a thrilling victory.
Defeat for Huddersfield, who have been beaten in 10 of their 12 Super League games this season, was further soured by the loss of centre Jake Connor to a serious-looking ankle injury just before half-time.
Wigan coach Shaun Wane: "Just to grind out a win like that, I'm very happy at getting two points against a really good team.
"They are a very good team and were desperate for a win. They are in a false position."
Huddersfield coach Paul Anderson: "We were under the pump, some of it was our doing, but our effort, endeavour and resilience was unbelievable.
"I'm proud and delighted because I can see us starting to get back into our defensive groove.
"The players are devastated and I made them get their heads up because I know if we continue like that, we'll get wins."
Wigan: Sarginson; Charnley, Gelling, Gildart, Tierney; Gregson, Smith; Mossop, Powell, Flower, Bateman, Isa, Sutton.
Replacements: Clubb, Tautai, Burke, Wells.
Huddersfield: Brierley; McGillvary, Cudjoe, Connor, Murphy; Brough, Wood; Johnson, Hinchcliffe, Huby, Wardle, Ta'ai, Lawrence.
Replacements: Rapira, Leeming, Mason, Roberts.
Referee: Joe Cobb