RICHMOND, Va. — Joey Logano pulled away after a restart with about 20 laps to go to win the NASCAR Cup Series race Sunday at Richmond International Raceway.

Logano, who qualified fifth but had to start 37th after making a transmission change, grabbed the lead from Penske Racing teammate Brad Keselowski on an earlier restart when Keselowski had to make a defensive move to keep Kyle Busch from passing him on the inside.

“I was driving my guts out out there,” Logano said. “That’s all I had. We won with a car that may not have been a winning car, so that’s something to be very proud of as a team. That means the execution was there and we were able to put ourselves in position to race there hard at the end. Brad was the fastest car. He was so fast.”

Keselowski got stuck behind some slower cars on the restart, letting Logano pull away.

“I think what we needed was about 10 more laps,” Keselowski said.

Logano had to get around Kyle Larson and five others who stayed on the track when everyone else pitted with just over 20 laps remaining. He made quick work of that challenge and pulled away while Keselowski and Denny Hamlin dueled for the second position.

Keselowski, who had the dominant car for the second half of the race, held on for second, followed by Hamlin, Ricky Stenhouse Jr. and Kevin Harvick.

“We just didn’t have the speed that the other cars had,” Hamlin said. “We finished right where we should have.”

Ryan Newman, Jimmie Johnson and Dale Earnhardt Jr. all took a chance when the rest of the field started making green-flag stops with about 80 laps to go. The three stayed out hoping for a caution flag that would have allowed them to get new tires and remain up front.

Johnson eventually pitted, and then he brought about the caution when he side-swiped Earnhardt into the wall in the backstretch, making the gamble pay off for Newman, who was likely to be passed shortly thereafter by the hard-charging Keselowski.

Pole-sitter Matt Kenseth led the first 163 laps, winning Stage 1, and raced in the top 10 all day until a flat tire with 35 laps to go.