RICHMOND, Virginia — Joey Logano went from last to first in the Toyota Owners 400 Monster Energy NASCAR Cup Series race at Richmond International Raceway on Sunday to claim his first win of the season in his 300th career Cup Series start.

Logano started the race in the back of the field after his team changed his transmission pre-race.

Brad Keselowski took runner-up honors to give Team Penske a 1-2 finish.

“Disappointed not to bring it home, but that’s just the way these things fall with double-file restarts and half the field staying out and half the field not,” Keselowski said. “You kind of take the good with the bad on those deals.”

Denny Hamlin, Ricky Stenhouse Jr. and Kevin Harvick finished third through fifth, respectively.

“We were competitive and our car drove really good,” Hamlin said. “We were just missing some of the speed from the 2 [Keselowski] and the 22 [Logano]. They run a little more sideways than what we run, and just, they have more grip. I think we optimized our day, for the most part, and that’s about as good as we could do.”

Logano and Keselowski stayed out during a caution with 34 laps remaining to restart on the front row. As Keselowski battled Kyle Busch, Logano took command of the lead.

“I didn’t really discuss it [pit strategy] much with Todd [Gordon, crew chief],” Logano said. “My thought process was, ‘Oh no!’ right after we stayed out, but we were able to maintain the lead. I don’t think we would have been able to win the race and hold off Kyle [Busch] if it had stayed green.

“The caution came out. The boys had a great stop, which gave us good track position to pass the cars that stayed out. We were able to have a good start, work our way past those cars and tried to take off the best I could.”

The yellow flag waved one final time — the ninth time in the race — 10 laps later, and Logano led most of the lead-lap cars down pit road. He was first off pit road, but restarted seventh behind six cars that stayed out.

Kyle Busch got out of the pits right behind Logano but was penalized for a commitment-line violation. Logano retook the lead with 16 laps remaining.

Keselowski was up front early in the second half of the race, but he lost leads to Hamlin on pit road twice. Hamlin and Harvick beat him off pit road during the caution that started the third stage and second half of the race. Keselowski retook the lead with about 164 laps remaining.

When the yellow flag waved again for debris with 149 laps to go, Hamlin again beat Keselowski off pit road, but Keselowski retook the lead with 114 laps remaining.

Keselowski then came out behind Harvick and Hamlin during a cycle of green-flag stops with about 80 to go after waiting one lap later to pit, but they battled for fourth in the running order while three other drivers — Dale Earnhardt Jr., Ryan Newman and Jimmie Johnson — stayed out, hoping to get to pit under caution. The caution came, but it was for hard contact between Earnhardt and Johnson.

“I just have to try to figure out if I just didn’t hear it being told to me [that Earnhardt was beside him] or if it wasn’t told to me,” Johnson said. “I just feel terrible, obviously. Man, I’m surprised our cars even kept rolling after that, because I just body-slammed him into the wall, and I could have easily not heard the clear or something else happened. I don’t know, but that’s the last thing you want to have happen with a teammate.”

Newman, meanwhile, was able to get back on the pit sequence of everyone else when they returned to pit road during the Earnhardt/Johnson caution.

When the race restarted, Keselowski retook the lead.

Matt Kenseth dominated in the first half of the race. After starting on the pole, he led the first 163 laps of the 400-lap race. As a result, he won the first of two 100-lap stages in the first half of the race. The laps led at Richmond on Sunday were the first laps Kenseth led this season.

After Kenseth claimed his first stage win of the season, so did Keselowski, who won the second 100-lap stage after passing Kenseth for the lead on lap 164.

Keselowski was in sixth place at the end of stage one. He got off pit road fifth at the start of the second stage and was battling Harvick for second by lap 140. He took the spot by lap 160.

After getting passed for the lead, Kenseth battled a tight race car, but held on for a second-place stage finish. He had trouble late in the race, though. After suffering a cut tire with 35 laps remaining, he went a lap down.

Stage two ran caution-free after the yellow flag waved twice for single-car incidents in the first 100 laps — for Erik Jones after a cut left-front tire sent him into the wall on lap 6 and again on lap 66 when Ricky Stenhouse Jr. made contact with the wall. Jones went to the garage after his incident, but Stenhouse was able to continue.

“Well, we got three-wide right on the start, and then the 5 (Kasey Kahne) ran us up into the fence,” Jones said. “I was trying not to wreck everybody, and we got run into the wall by the 5, and then a couple of laps later, we cut a left-front, so it’s really unfortunate. We only made five laps. Ten laps of the race, and we’re already out, so it’s just, really, a heartbreaking day.”

NOTES: Thirteen teams were docked practice time during the Richmond race weekend, 11 of those because of inspection issues the last three race weekends at Texas Motor Speedway, Bristol Motor Speedway and Richmond. Ricky Stenhouse Jr. lost practice time both Friday and Saturday. Austin Dillon had to start the race in the back and lost pit selection, in addition to losing practice time, because of inspection problems. … Joey Logano qualified fifth but started the race in the back after his team changed his transmission. … Kyle Larson won the NASCAR Xfinity Series race at Richmond on Saturday. Cup Series drivers Dillon and Ryan Blaney also finished in the top five. … Carl Edwards won the 2016 Toyota Owners 400. Denny Hamlin won the most recent race at Richmond last September. … Kyle Busch leads active drivers with three Richmond wins. Dale Earnhardt Jr., Kevin Harvick, Jimmie Johnson and Denny Hamlin have three Richmond wins apiece. … Johnson headed into Richmond as winner of the last two races at Bristol and Texas.