Huddersfield Giants will end the regular season at the foot of Super League after Daryl Clark's late try earned a 34-30 victory for Warrington Wolves, who climb to second.
The Giants - who will now battle to retain their top-flight status in the qualifiers - led on three occasions at Halliwell Jones Stadium, former Wolves winger Gene Ormsby grabbing a hat-trick of tries against his old club.
However, it was the hosts who came out on top to avenge an 11-0 defeat at Huddersfield in April and move within a point of league leaders Hull FC heading into the Super 8s.
Warrington started brightly, Stefan Ratchford and Ben Currie crossing, but trailed when two tries from Ormsby sandwiched an Aaron Murphy score.
A converted Ben Westwood try put the Wolves back in front, only for Nathan Mason to respond for the Giants early in the second half.
Chris Sandow and Ryan Atkins touched down to give Warrington an eight-point lead, yet Huddersfield looked set to claim victory when Ormsby's hat-trick score was followed by a Craig Huby try that Danny Brough converted.
It was hooker Clark who had the final say, however, scoring from a free play with three minutes remaining to secure his side's third successive win.