Denny Hamlin easily clinched his spot in the Chase for the Sprint Cup championship by winning Sunday night's AdvoCare 500 at Atlanta Motor Speedway.

Hamlin beat Martin Truex Jr. out of the pits to take the lead during a caution in the closing laps. The caution, which came for an incident involving Jamie McMurray, set up a green-white-checkered finish.

After the final restart, Hamlin pulled away from the field, while Jeff Gordon and Brad Keselowski passed second-place runner Truex. Hamlin held off a last- lap challenge from Gordon, beating him to the finish line by 0.38 seconds for his Sprint Cup Series-leading fourth win of the season. He also won last weekend at Bristol.

"The pit crew won me the race," Hamlin said after claiming his 21st career win in NASCAR's premier series. "That's what a championship team is all about when you have all the pieces of the puzzle put together, and I think this year, we have it all."

Hamlin led a race-high 105 laps. His fourth win puts him in position to start the Chase in the first seed. The series will conclude its regular season next Saturday night at Richmond before the 10-race playoffs begin on Sept. 16 at Chicagoland.

"This is the one I wanted really bad," he said. "The last win (Bristol) was a big win, no doubt about it, but I've been really good here at Atlanta and not won it the past few years."

Keselowski finished third, while Truex placed fourth. Truex led for 40 laps before the sixth and final caution. He was attempting to end his 191-race winless streak. His first victory in the series came in June 2007 at Dover.

"It just wasn't meant to be again, I guess," Truex said in disappointment.

Kevin Harvick led a total of 101 laps but faded late in the race and finished fifth. Kyle Busch, Dale Earnhardt Jr., Paul Menard, Matt Kenseth and Mark Martin completed the top-10.

Kenseth, Hamlin, Keselowski, Truex and Clint Bowyer, who finished 27th, secured their positions in the Chase based on points. Greg Biffle, Earnhardt Jr. and Jimmie Johnson locked down their spots at Bristol.

Tony Stewart, currently 10th in the point standings, is guaranteed at least a wild card due to his three wins this year. The defending series champion started on the pole for Atlanta but struggled throughout the race to finish one lap down in 22nd.

Just two positions remain available for the 12-driver Chase field. Despite finishing 23rd, Kasey Kahne kept the first wild card spot, while Busch moved back into second in the wild card rankings.

Gordon is third, trailing Busch by 12 points.

"I got everything I could ask for," Gordon said after his second-place finish. "I got the restart I wanted. On that restart, I got to the outside, but I was a little too tight. Denny was pretty good there, but he made a mistake coming off of (turn) two. I made a run on him, but I made a bad decision.

"I should have run into the back of him going into three and moved him up the racetrack. We would be sitting in victory lane right now and counting another win."

Carl Edwards and Ryan Newman now have slim chances of making the Chase. Edwards finished 36th after suffering engine failure in the late going. He would have to win at Richmond to have any possibility of qualifying for the playoffs.

"This year has just been amazing in a bad-luck kind of way," said Edwards, who finished second to Stewart in last year's Chase. "We're going to Richmond where anything can happen, and hopefully what ever happens, it involves us winning the race and making the Chase. We don't quit."

Newman finished 35th after he was involved in an accident with Johnson and Sam Hornish Jr. on the backstretch just after a restart on lap 270.

"I didn't see much, but I know I got run out of room, and it wasn't my fault," Newman said. "It looked like the 48 (Johnson) just ran everybody out of room, and it was unfortunate."

Newman is fifth in the wild card rankings, while Edwards, who has yet to win a race this season, is seventh.