MARTINSVILLE, Va. (AP) Denny Hamlin just needed a visit to Martinsville Speedway to get his racing team back on track.
Now, with his spot in NASCAR's Chase for the championship virtually assured, they can work to make it better.
Hamlin passed teammate Matt Kenseth for the lead with 28 laps to go Sunday and ended Toyota's 32-race winless streak in the NASCAR Sprint Cup race at Martinsville Speedway. It was his fifth victory on NASCAR's oldest, smallest circuit.
''We had a very fast car, but obviously some pit road issues, but we overcame it,'' Hamlin said after his 25th career victory, which was helped along by a serious blunder that took four-time champion Jeff Gordon out of contention late.
Hamlin's pit crew, unlike Gordon, made their mistake early enough in the race to recover. Before the event was 200 laps old, Hamlin was penalized when his crew failed to control a tire on pit road. It dropped him from the lead to 22nd place.
He was back in the top 10 by the midpoint, and stalking the leaders shortly thereafter.
''The last 60, 70 laps played out how they needed to play out for us to win today,'' Hamlin said.
Hamlin also held off a five-lap, bumper-to-tail challenge from Brad Keselowski at the finish. There was some bumping and nudging, and a big wiggle for Hamlin in the final fourth turn, but Keselowski never caused him to spin.
''We just weren't going to be denied today, and hats off to Brad,'' he said, thanking Keselowski for not wrecking him.
''I did everything I could other than wreck him,'' Keselowski said.
The race was run without reigning rookie of the year Kyle Larson, who watched from a North Carolina hospital where he was undergoing testing after fainting at an autograph session on Saturday. Regan Smith drove in his absence, finishing 16th.
Keselowski was second, followed by Joey Logano, Kenseth and David Ragan, giving Joe Gibbs Racing three cars in the top five. The jolt was especially appreciated in a week when the team announced that President J.D. Gibbs is being treated for a ''symptoms impacting areas of brain function,'' an issue that has left doctors with very few answers thus far.
It was J.D. Gibbs who discovered Hamlin on a North Carolina short track, and Joe Gibbs thought of that near the end.
''For me it was emotional and thinking about J.D. and all that he means to our team, so it was a big week for us, but a great finish to a story there,'' Gibbs said.
Logano, the pole-sitter, was trying to become the first driver to sweep a weekend at Martinsville, having won the truck race on Saturday. He led 109 laps, but said his car at the end was not as strong as the leaders.
Gordon, an eight-time Martinsville winner, took the lead for the first time with 58 laps to go and then got caught entering pit road too fast when the 16th and final caution came out with about 40 laps to go.
The mistake put him well back in the field, and while he rallied to finish ninth, was left disappointed.
''Wow. I'm sorry guys,'' he said on the radio when told of the penalty. ''That's on me. I apologize.''
Gordon said he knew he was pushing the limit, knowing he had a chance to win the race.
''I thought with our track position there at the end, we had a shot at it,'' he said. ''Oh, my gosh, I'm so disappointed. I don't even know what to say right now. Of course, then the car is the absolute best it has been all day ...''
The race also ended Kevin Harvick's streak of top-two finishes at eight. Harvick, who was three races shy of tying Richard Petty's record of 11, set in 1975, led a race-high 154 laps, but got caught in the outside lane on a restart and faded to eighth.
''Just lost track position at the wrong time,'' the defending series champion said.
Gordon and his Hendrick Motorsports teammates have dominated at the 0.526-mile oval in recent years, but Gordon's finish and an 11th for Kasey Kahne were the best they could muster. Dale Earnhardt Jr., who won here last fall, wound up in the garage after losing his radiator in a large crash in turn one before the midpoint of the race, and Jimmie Johnson, an eight-time Martinsville winner, had issues throughout and finished 35th, 32 laps down. Earnhardt finished right behind him.
The race also marked the Cup debut of Chase Elliott, who will replace the retiring Gordon in the Hendrick stable next season, and Elliott got a quick welcome. His car was bounced around early, also wound up in the garage and finished 38th.
The day went better for Danica Patrick, who was seventh, her fifth career top-10 finish. That tied her with Janet Guthrie for most top-10s by a female driver, and was one spot off Patrick's career-best sixth place run at Atlanta last year.
''It's disaster to be off and struggling with the car and it's really fun to have a good car,'' Patrick said.