DARLINGTON, S.C. – Denny Hamlin overcame a bad miss of the pit road entrance, chasing down Martin Truex Jr. with three laps left to win the Southern 500 at Darlington Raceway on Sunday night.

Hamlin checked up after sliding by the entrance with 54 laps left and fell behind Truex by 20 seconds. But Hamlin slowly reeled in Truex and passed him when his rival brushed the wall and got a flat tire.

"This is a good day all in all," Hamlin said. "So proud to be back in Victory Lane in the Southern 500."

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.

Hamlin swept the weekend at Darlington, having won the Xfinity race Saturday.

Kyle Busch was second, followed by brother Kurt Busch.

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

"We can still do this," Hamlin's crew chief, Mike Wheeler, told his driver after the miscue.

So Hamlin started the comeback. He got up to Truex's bumper with three laps before moving low around lapped traffic to take the lead. Truex rubbed the wall, 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 — right where he started — in his final race at Darlington.