Liam Farrell's last-minute try snatched a thrilling win for Wigan after St Helens looked to have staged a remarkable comeback victory.
The visitors, missing six first-team regulars, had seen a 10-0 lead turn into a 22-10 deficit by the hour mark.
But Tommy Makinson's try and a penalty by Jamie Foster pulled them back in front and on course to top the table.
On the last play of the game, though, Farrell went over for his side's fifth try of the day to clinch a famous win.
Saints, who have a great record in recent seasons on Wigan soil, came into the game on a run of five straight victories.
Added to that, Wigan had lost three of their last four home games.
But Saints were also ravaged by injury. And, although they opened up a 10-0 lead through tries by Michael Shenton and Foster, their problems grew when they lost Paul Wellens and Gary Wheeler inside the first half-hour.
Joel and Sam Tomkins were both involved in the build-up to Wigan's opening try, Josh Charnley going over after a neat reverse pass.
And last season's Man of Steel Pat Richards then claimed his first try of the season shortly after half-time, as Wigan closed the gap.
The Tomkins brothers then combined again to set up another Charnley score as Wigan took the lead for the first time.
And, when George Carmont created the opening for Richards to notch his second, Wigan looked comfortable with a 22-10 advantage.
That was the cue for a superb Saints fightback.
Francis Meli set up Foster's second try, which he converted himself from the touchline. And Makinson's first Super League try gave Foster the chance to convert and draw his team level, which he duly did.
With seven minutes remaining, Carmont gifted St Helens a chance to take the lead when he dropped on the ball in an offside position and Foster's penalty put the visitors ahead.
Wigan went all out in search of a late victory, with Saints captain James Graham denying Sam Tomkins with a flying tackle, and Richards twice going close to bagging his third try of the afternoon.
But, just when Saints looked to have done enough to survive and claim an sixth win on the ground in seven years, Farrell came up with the goods.
From Paul Deacon's short pass, he found a gap in the defence to dive over from close range, and Richards' boot rounded off a dramatic derby victory.
Wigan coach Michael Maguire said: "It was a real rollercoaster. My heart is still racing. It means a lot to a lot of people in this town. I'll definitely miss this place.
"I'm extremely pleased for the boys for way they dug in. We started off a bit slower than we expected but we had a good chat at half-time and came out and did the things we'd practised.
"We stuck to the plan and luckily enough came up with a try. It was great to see the boys play for 80 minutes."
St Helens coach Royce Simmons said: "Paul Wellens was one of quite a few players who had needles before the game. We took the risk and it didn't work. He won't be right for a couple of days.
"And there's probably another two or three who won't be right. Gary Wheeler's done his AC joint so he'll be out for a long time and that's our third half-back sitting on the sidelines.
"We've only got four so Jonny Lomax is pretty sure of getting a run. And there are a few boys playing in the Under-20s who might get a surprise."
Bookmark with:
What are these?