AP photo by Charlie Riedel / NASCAR driver Denny Hamlin celebrates after winning Thursday night's Cup Series race at Kansas Speedway.

KANSAS CITY, Kan. — These days, three straight finishes outside the top 10 in a NASCAR Cup Series race counts as a rough patch for Denny Hamlin.

Thursday night at Kansas Speedway, things were once again as smooth as can be for the Joe Gibbs Racing veteran.

Hamlin hung around the front of the pack all night, avoiding trouble that cost several playoff contenders in the final stage, then breezed past Kevin Harvick for the lead in the closing laps. Hamlin then held off charging Brad Keselowski for his series-leading fifth victory of the season and the 42nd of his career. He also won for the second straight time at Kansas Speedway.

"I don't know if we had the best car. We definitely had a top-three car all day," Hamlin said after his burnout in front of the empty grandstands. "We just went for it there at the end. The pit crew did an amazing job getting us out there in front."

Hamlin, 39, matched his wins total from the 2012 season and is one short of tying last year's mark. His only season with more victories was 2010, when he won eight times on the way to a runner-up finish in the points standings. This year he has won the season-opening Daytona 500, as well as at Darlington Raceway, Homestead-Miami Speedway and Pocono Raceway in addition to Thursday's victory.

He had struggled in the past three points races, though, failing to finish better than 12th at Indianapolis Motor Speedway, Kentucky Speedway and Texas Motor Speedway. After showing good speed early in Thursday's race, his JGR No. 11 Toyota team made all the right calls during a crash-filled final stage. Team Penske's Keselowski finished second in a Ford, JGR's Martin Truex Jr. came across the line third and Stewart-Haas Racing's Harvick — who was going for his fifth win of the year — wound up sliding to fourth. Erik Jones was fifth to cap a big night for JGR

Hendrick Motorsports driver William Byron led the race as the 22-year-old chased his first Cup Series victory, but he slid backward after a late caution and wound up finishing 10th. Teammate Alex Bowman also made a charge to the lead but finished behind SHR drivers Aric Almirola and Cole Custer in eighth. Chip Ganassi Racing's Kurt Busch was 10th.

some text
AP photo by Charlie Riedel / Alex Bowman (88), William Byron (24) and Kevin Harvick (4) battle for position during Thursday night's NASCAR Cup Series race in Kansas City, Kan.

The youngsters wound up leaving it to the veterans to battle it out over the final laps.

"We got to the lead, but we just went dead sideways after about four or five laps," sad Harvick, who still holds the points lead at 763, with Hamlin second at 634 and Keselowski third at 666. "We were just holding on hoping for another restart, because we could hang for a couple laps."

Truex may have had the fastest car on the track by the end of the night, which began with temperatures in the mid-90s and a heat index approaching triple digits, but he ran out of time to chase down his teammate.

"It would have been difficult to pass him," Truex said about Hamlin. "It was a battle all night just to get track position. These things are so difficult in traffic. You lose a few more spots than you hope on a restart and you just have to dig."

Penske's Joey Logano led early before his night really ended in disaster — and took some playoff contenders with him.

The 2018 Cup Series champion's problems began when a tire got loose on pit road during the first stage, sending him to the back. Logano was working his way forward early in the final stage when his left front tire went down, sending him into the outside wall. Matt DiBenedetto and Jimmie Johnson, the last two drivers on the good side of the playoff cut line, sustained heavy damage as the field checked up. So did Austin Dillon, who was the surprise winner this past Sunday at Texas.

"I'm pretty freaking irritated. We've had garbage luck the last few weeks," DiBenedetto said. "We have no horsepower. It takes us 45 minutes to get going. The restarts are just wild. But that's what is happening."

Logano said he felt his tire going down just before green but thought "it wasn't bad."

"Maybe it was bad judgment on my part," Logano said, "and I didn't want to lose any track position for something that wasn't bad. It's one of those judgment calls. I just feel bad for everyone else."

Another wreck during the next always chaotic Kansas restart collected Ryan Preece, Chris Buescher, Ryan Newman and Christopher Bell. Preece hit the inside wall with such force that his car leaped several feet into the air.

It would have been an exciting show for fans if there were any in the stands. After about 20,000 wore masks and braved stifling heat in Texas, the grandstands were again empty at Kansas. Soaring numbers of positive COVID-19 tests have forced track officials to run this week — including upcoming races in the Xfinity, Truck and ARCA series — without any fans.

The next Cup Series race, Aug. 2 at New Hampshire Motor Speedway, can have about 19,000 fans. The following weekend at Michigan International Speedway, which will host Cup Series races on back-to-back days, will not have any.

JGR's Kyle Busch finally had something go right during his frustrating season. The 2019 series champ, whose only win in his past 41 starts on NASCAR's top circuit came in last year's finale, held off Hamlin and Truex to earn his first stage win this year. He finished 11th.

It was another race between teammates in the second stage. This time, it was Keselowski getting around Ryan Blaney — who was dominant at Texas but failed to win — on the penultimate lap to take the stage.

Ricky Stenhouse Jr.'s challenging year continued when he went to the garage early with a mechanical problem. It also was a rough night for Bubba Wallace, who spun early in the race coming out of the fourth turn, then plowed into Matt Kenseth when he spun in the middle of the same turn early in the final stage.

"We've had some really bad weeks," Stenhouse said. "Lost the balance a little bit but felt like we were pretty close. But I don't know, a fire started in the cockpit. Something electrical in the dash."