DARLINGTON, S.C. (AP) — Denny Hamlin had strong motivation to chase down Martin Truex Jr. after badly missing pit road at Darlington Raceway – embarrassment.

Hamlin turned a strong lead into a 20-second deficit when he missed the entrance – “Kind of a rookie move,” he said – yet rallied over the final 50 laps to pass Truex and win the Southern 500. It was a dramatic turn of events that had Hamlin relieved he would not be remembered for blowing a certain win.

“I was hoping it would (turn out this way),” he said, “or else I would’ve looked pretty silly trying to explain why we lost.”

No explanations necessary, expect maybe, how the heck did Hamlin do it?

“I think it’s a great story,” car owner Joe Gibbs said. “You can tell when he goes to certain racetracks, too, that he’s got some favorites that he’s awful good at and this is one of them.”

Hamlin won both Darlington races for the second time in his career, the other coming in 2010. He has won seven times in the two series at Darlington.

Hamlin sure didn’t think he’d celebrate anything after his error with 54 laps left as he fell behind Truex by some 20 seconds. But Hamlin slowly reeled in Truex and passed him with three laps left when his rival brushed the wall and got a flat tire.

at Darlington after winning the Xfinity race Saturday. Truex won the first two stages, clinching NASCAR’s regular-season championship and gaining the No. 1 seed heading into the playoffs in two weeks.

Kyle Busch was second, followed by brother Kurt Busch, Austin Dillon and Erik Jones.

Hamlin led 124 laps and looked as if he was easily on the way to a second Southern 500 after winning in 2010. Then inexplicably, Hamlin missed the entrance and seemingly threw the race to the ever-steady Truex.

“We can still do this,” crew chief Mike Wheeler told Hamlin after the miscue.

Hamlin got up to Truex’s bumper with three laps to go before moving low around lapped traffic to take the lead and hold on for victory.

“This is a good day all in all. So proud to be back in victory lane in the Southern 500,” he said.

, blew his right front tire and stumbled home in eighth.

“Sometimes it’s just not your night,” Truex said. “Tonight wasn’t our night.”

Dale Earnhardt Jr. finished 22nd – the same as how he started – in his final time racing at Darlington. On Friday, the track rechristened one of its suite buildings in turn three as “Earnhardt Towers” in honor of Dale Jr. and his late father Dale Earnhardt, who won nine times at Darlington.

Matt Kenseth was sixth, Ryan Newman seventh, then Truex, pole-sitter Kevin Harvick and Jamie McMurray rounding out the top 10.

It’s the second time Hamlin has swept events at Darlington, winning both the Xfinity and Cup races together in 2010 and this year. Hamlin passed Joey Logano coming off the final turn to take Saturday’s race.

BAD WEEKEND: A poor weekend on the track got worse after the race when Dale Earnhardt Jr.’s car was found to have two loose lugnuts in inspection.

EYE ON THE TRUCKS: Brad Keselowski finished 15th, but was asked about his truck series driver, Austin Cindric, who won the NASCAR Camping World Truck race in Bowmanville, Ontario. Cindric’s win clinched a spot in that series’ playoffs. “It’s always good to get a win in that series,” he said. “That’s a good deal for the whole team.”

WHO’S HOT: Kyle Busch came to Darlington off a sweep of the truck, Xfinity and Monster Energy races at Bristol two weeks ago. Busch wound up second and led six laps on the way to his 10th top-five finish of the season.

WHO’S NOT: Clint Bowyer had hoped the spirit of Mark Martin – Bowyer’s car carried a paint scheme in tribute to Martin – but instead Bowyer was out of the race just 18 laps in with a broken valve. Bowyer, who came in 17th, in points, is on the outside looking in on NASCAR’s 16-team playoff picture and would need a last-ditch win at Richmond next week to keep going.

UP NEXT: Richmond International Raceway, Sept. 9. Hamlin is the defending race winner.

More AP auto racing: