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: 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