Carl Edwards grabbed the lead from Kevin Harvick on pit road with 24 laps to go Friday night and won the NASCAR Nationwide Series race at Richmond.

The victory finished off a remarkable race for Edwards, who had to start at the back of the field after his team made adjustments to his Ford after the field was impounded.

The work and penalty were clearly worth it as Edwards steadily worked his way into contention, first challenging Denny Hamlin for the lead with 70 laps to go.

"I thought I'd lost the race," Edwards said. "I got in deep behind Denny, he checked up a lot more than I thought he was going to, I hit him and I let off and (Harvick) got by me."

Edwards faded afterward, but when a caution for debris on the track flew on the 226th lap, the leaders all headed for pit road, and Edwards beat Harvick back to the track.

"My guys are the ones that made this one happen, the guys in the pits," Edwards said.

Racing with a broken right foot and the most important race of the season looming on Saturday night, Edwards opted for a standard victory lap rather than his usual backflip.

"It's not the weak link right now. It's not holding me up any and it feels good, so it shouldn't be an issue," Edwards said after using crutches to get to the media center.

Harvick finished second, followed by Kyle Busch, Brad Keselowski and David Reutimann.

The victory allowed Edwards to gain 20 points on Busch in the standings, but he still trails by 201 points with eight races remaining, and Busch would have to falter badly.

"These guys have picked up some grip somewhere," Busch said. "I don't think we've lost anything. These guys have just gotten better. We've got to do some homework."

For much of the race, local favorite Hamlin looked like the guy to beat, even though several bad pit stops cost him position. Once he went in as the leader and came out third, and another time he went in running second and emerged sixth, then began making up ground.

Only Edwards had a better car, especially on long green-flag runs.

He caught Hamlin and pulled alongside him by lap 180, but Hamlin held his ground. Several laps later, Edwards gradually began to fade and Harvick passed him for second.

By lap 201, Harvick was the one stalking Hamlin's bumper. He tried to pass him on the inside, but Hamlin wouldn't yield until Harvick gained the lead in a side-by-side dual.

One lap later, Hamlin retook it and the cars continued to race side-by-side or nose-to-tail until Hamlin's Toyota wiggled in the fourth turn, causing him to nudge Harvick to keep from crashing. Harvick continued on unscathed, and Hamlin headed to pit road for tires.

"Typical here at Richmond," Harvick said of the contact.

The final caution came shortly thereafter, and that's when Edwards made his move, winning for the third time on the 0.75-mile oval, and for the 24th time in the series.