“Hey, man, we’re in this thing,” Gil Martin, Kevin Harvick's crew chief, exclaimed after Sunday’s Kobalt Tools 500 at Phoenix International Raceway.

For much of the last half of Sunday’s race, it appeared that something close to the opposite would be the case. Then bad luck became good luck for Harvick, and the worm turned.

Harvick fought back from late-race problems to finish sixth, avoiding disaster and actually gaining points on Denny Hamlin, No. 1 in the standings. Harvick will have a shot at the title in next week’s season finale at Homestead, FL, as he enters the race in third place, 46 points behind Hamlin and 31 behind second-place Jimmie Johnson.

Harvick’s Sunday took a bad turn with 90 laps to go as he had to re-pit because of a missing lug nut. That problem eventually became a boost, however, as Harvick, who had fallen from fifth place to 19th (and thus with little to lose by pitting again), came into the pits to top off his fuel tank for what turned out to be a green-flag run to the finish.

Hamlin, who had been running first or second most of the day, had to pit with 14 laps to go and fell back in the field. He finished 12th.

Harvick went through a series of emotions in the closing laps of the race.

“We’re just lucky, to be honest with you,” he said. “These guys on pit road do a great job and just made a mistake. I was pretty down because I thought, ‘There it went.’

“Richard [team owner Richard Childress] and Gil said, ‘Keep at it. You never know what’s going to happen.’ ”

What happened was a fuel-mileage finish, and Harvick, having refreshed his tank, was in good shape.

“We dodged one, for sure,” he said. “We still have a chance next week. That’s all you can ask for. I’ve got to thank Richard and Gil for keeping me pumped up.

“It all worked out in the end. The guys thought we were really close on fuel, and they thought we could make it, no problem. But they were still a little bit nervous about it, and our mistake wound up being one of the things that kept us going.”

Harvick has been known to bark about poor pit stops on his team radio, but he was calm Sunday.

“I wasn’t really mad,” he said. “I was just disappointed because I thought that it all had come out from underneath us.”

For Martin, the tension of the final miles was tough.

“I know there’s no stress test a doctor can give you that compares,” he said. “It was an emotional rollercoaster.

“Man, what can you say? We lived to fight another day.”

Mike Hembree is NASCAR Editor for SPEED.com and has been covering motorsports for 28 years. He has written several books on NASCAR, including "NASCAR: The Definitive History of America's Sport" and "Then Tony Said To Junior: The Best NASCAR Stories Ever Told". He is a six-time winner of the National Motorsports Press Association Writer of the Year Award.