DARLINGTON, S.C. (AP) Carl Edwards took the lead on the last pit stop and held off Denny Hamlin on a restart eight laps from the end for his first Southern 500 victory Sunday night.

Edwards was two laps behind early in the long, long, nearly five-hour NASCAR Sprint Cup race, slowed by a record 18 cautions at Darlington Raceway.

Pole-sitter Brad Keselowski was second and Hamlin finished third. Joey Logano was fourth, followed by defending race champion Kevin Harvick and the Busch brothers, Kurt and Kyle.

More from FoxSports

Edwards won for the second time this season, and gave Joe Gibbs Racing its seventh victory in the last 10 events. JGR swept the weekend, with Hamlin winning the Xfinity race Saturday.

Edwards did his signature victory backflip in the race's return to Labor Day weekend.

''I guess we made it Carlington for a couple of minutes,'' Edwards said after his crew taped over part of the ''D'' on the painted Darlington sign along a retaining wall. ''This is the Southern 500. This is amazing.''

Edwards has won multiple races in season for the seventh time in 11 seasons as a fulltime driver.

Keselowski started on the pole and by far led the most laps with 196. But he was beaten out of the pits by Edwards on Darlington's record-setting 18th caution period with 12 laps left.

Almost as much as drivers enjoyed Darlington's throwback paint schemes and retro-1970s theme, they loved the low downforce package given the cars - the same that was used to rave driver reviews in Kentucky earlier this year.

''Man, I loved it. This is as good as it gets,'' Edwards said about the low-downforce package. ''This is what it's about: sliding cars, the tires falling off. If there's any way we can run this in the Chase, I hope we do it.''

Keselowski agreed. ''It separates the race car drivers from the pretenders and that's the way it should be,'' he said.

Keselowski hoped to use Darlington to springboard into the Sprint Cup playoffs, which start in Chicago in two weeks. He said his team still has work ahead.

''We were definitely right there, just one spot short at the end,'' he said. ''We're right there. We've just got to find one more level to win these races and win this championship.''

NASCAR's regular season ends next week at Richmond, where the field of 16 contenders will be set.

NASCAR returned the Southern 500 to Labor Day weekend for the first time since 2003. The track, the sport's oldest superspeedway, closed NASCAR's summer as one of its crown jewel events for 53 years until losing out in Sprint Cup realignment.

But NASCAR leaders thought the time was right to put the iconic race back in its traditional sport. The race featured a 1970s, throwback theme, with 35 race teams racing in some retro paint scheme.

Kyle Larson, his No. 42 sporting the Mello Yello colors, came out for driver introductions in a curly wig with a mustache grown for the weekend. NBC Sports got into the spirit, too, having Hall of Famers Ken Squire, Ned Jarrett and Dale Jarrett in the TV booth to call some of the race.

While the hype was huge, the true throwback was Darlington, which was the same tire-chewing track that's beffuddled NASCAR's best for generations. Chase Elliott, running his last Sprint Cup race before slipping into retiring Jeff Gordon's seat in the No. 24 car next season, spun out just eight laps in to bring out a caution.

It was far from the last - for Darlington and for Elliott.

Bill Elliott's son, who won the Xfinity race here in 2014, was involved in another spin that took him out of the race for good.

Tony Stewart stayed out during one of the cautions while the field pitted and wound up leading for 10 laps, the first time he's run up front since Talladega last May. But Stewart was quickly run down by the pack of front runners, led by Harvick and Keselowski.