MARTINSVILLE, Va. -- Denny Hamlin and crew chief Mike Ford were in a tough spot, leading a race with a dominant car and eight laps to go when a caution forced a decision.

If they headed for pit road, the cars right behind them would stay on the track, gambling they could win a short sprint to the finish on old tires. And if they stayed on the track, the rest would pit, get fresh tires and surely run them down.

They picked pit road, and Hamlin made it work in a remarkable finish at Martinsville Speedway, rallying from ninth place by almost recklessly bull-rushing his way through the field during a pair of two-lap sprints on the shortest, oldest track in NASCAR.

Hamlin passed Ryan Newman, Matt Kenseth and leader Jeff Gordon following the final restart to earn his third career victory here.

''That's hard to do. I had to bully my way through there towards the end, but everybody was just running into everyone,'' Hamlin said of his surge from the outside of the second row. ''I flattened my tire with Kenseth going down the backstretch and just somehow made it work.''

First, he hugged the inside into the first turn, forcing three-wide racing that almost never leads to good things, especially on a narrow 0.526-mile oval. He plowed his way into fourth before teammate Kyle Busch spun out, bringing out a very timely caution.

Ahead of him, Gordon was poised to cross the start-finish line and take the white flag, which almost certainly would have allowed him to win the race with the lead Hamlin handed him. But when the yellow flew before Gordon got to the line, a two-lap sprint was required.

''We had the thing wrapped up,'' Gordon said.

And then he didn't, and Hamlin had one more power move to make. He pushed Newman out of the way on the restart, then watched as Kenseth and Gordon dueled. Both eventually slid up the track on older tires, allowing Hamlin to dart underneath for the victory.

''What can you do? When you're the leader, it's bad in a lot of different ways on a short track because you're at the mercy of the guy behind you,'' Hamlin said.

Gordon said NASCAR threw the caution when Busch spun to set up the finish.

''It was pretty obvious to me that NASCAR wanted to do a green-white-checkered finish,'' he said. ''There were cars blowing tires, hitting the wall, and they weren't throwing the caution. One spins out, and they throw the caution in the blink of an eye.''

The race originally was scheduled for Sunday, but was postponed by rain. The finish delighted about 30,000 fans who came out to watch on a work day.

Hamlin's Joe Gibbs Racing teammate, Joey Logano, was second, followed by Gordon, Newman and Martin Truex Jr. Four-time defending series champion Jimmie Johnson was never in contention to win, but finished ninth and assumed the points lead by 14 over Kenseth.

He had a great view of the finish, too.

''It looked pretty crazy from where I was sitting,'' he said.

All day, the race shaped up as a two-car battle between Hamlin and Jeff Burton, with the Virginians leading almost all of the final 300 laps. That was until Hamlin and Busch pitted with eight laps to go, handing Gordon his first lead since early in the race.

Burton lost a tire with eight laps left, causing the caution, and wound up 20th.

Gordon has won seven times at Martinsville, most among active drivers, and was fully aware that Hamlin had fresh tires and aimed to take the lead back on the last restart.

''All I can tell you is you know it's gonna get wild and crazy,'' Gordon said.

The day was a long one for Kevin Harvick, who started the day as the points leader, led the first 44 laps after starting on the pole and was running in the top five when something broke on his car and he headed to the garage. When he returned, he was 34 laps behind.