"Only a handful of those kind of finishes ever happen like that," Dungey said after spraying champagne on his crew. "I was kind of fortunate, but I will take it."
Millsaps finished second, while Weimer was third and Justin Brayton fourth.
Dungey, the 2010 champion, admitted revenge was on his mind when Weimer took him out on lap 8, but he served up the payback the best way he could passing Weimer and then overtaking Millsaps to take the checkered flag.
"The way we did it was even better [than exacting revenge on Weimer]," Dungey said.
Said Millsaps, who won the holeshot for the fourth time this year: "I led 19 laps out of 20, and I lost. It kinda sucks, but that's racing."
Weimer also acknowledged some mistakes.
"I kinda fell apart a little bit at the end," he said. "I kinda messed up [when Dungey passed him] and he was going so much faster than me, and then he was gone."
Series champion Ryan Villopoto, who clinched a few weeks ago, missed the race with a knee injury suffered last week in Seattle. Dungey is fourth in the points race with just one race left next week in Las Vegas while Millsaps stayed in second and Brayton in third.
Racing also got crazy in the Lites (250 cc) main event as well, as Eli Tomac of Cortez, Colo., passed leader Jason Anderson on the ninth lap and held Anderson off to win. The victory clinched the West Coast Series Championship for Tomac, who passed Dean Wilson in the bowl turn a few laps before overtaking Anderson.
Wilson then went down hard near the finish line during lap 12, drawing a collective gasp from the crowd.
"It was huge to close out the night with a race win and a championship," said Tomac. "That was some good racing out there."
There was a rare crash at the start of the Lites Parade Lap basically an exhibition lap when Anderson and Ryan Sipes got tangled up. Sipes' mechanic started kicking the Yamaha's front tire for a quick repair.
Weimer won the Supercross first heat easily, leading from start to finish, to qualify for the main event.
The biggest name failing to qualify after the heat was Josh Grant of Corona, Calif., a Kawasaki rider, but he finished second in the Last Chance Qualifier (Robert Kiniry was first) to make the main event.
Millsaps, a Floridian who now lives in Murrieta, Calif., won the second heat aboard a Yamaha.
Tomac won Heat 2 in the Supercross Lites West, while Dean Wilson took Heat 1 an hour or so before the big crash in the Lites main event.
R Supercross in Salt Lake City
• Ryan Dungey of Belle Plaine, Minn., won the main event, passing David Millsaps on the next-to-last lap
• Eli Tomac of Cortez, Colo., won the Super Lites main race
• Weather conditions were close to perfect, just a tad chilly, for the riders and crowd of 40,548