MARTINSVILLE, Va. — Kevin Harvick’s nearly perfect season came to a spinning and sudden halt Sunday when he was bounced from the playoffs in a stunning upset at Martinsville Speedway.

Chase Elliott, of Dawsonville, Ga., won the high-stakes race to earn his first berth in the championship four. It knocked Harvick, a nine-race winner and the regular season champion, from the title round after a stunning collapse and a season spent as the favorite to win the Cup crown.

Harvick was mediocre at Martinsville and fell a lap off the pace after a flat tire. He spent most of the race below the cutline, desperately chasing points at NASCAR’s oldest and smallest speedway. He was racing for the fourth and final slot in the field, trying to catch Denny Hamlin or Brad Keselowski, in a three-race push for the one final spot.

Elliott — the son of racing legend Bill Elliott — scored a must-win victory that put him in the finale after three previous failures to advance. It’s a huge professional on-track accomplishment for NASCAR’s most popular driver and gave the beloved Elliott family its first Martinsville trophy grandfather clock.

Bill Elliott was 0 for 45 at Martinsville in his Hall of Fame career, and Chase Elliott won in his 11th try.

“It’s the biggest win ever for us,” said Elliott, who earned his 10th Cup victory and career-high fourth of the season. “I’ve never been in this position before and it’s exiting.”

NASCAR this season moved Martinsville to the final elimination race in an effort to turn the .0526-mile paperclip into a short track throw-down. It made for 500 white-knuckled laps in which the contenders all showed up to win but also had in-race bobbles.

Elliott had back-to-back bad pit stops, including one late in the race in which Elliott could have drawn a race-crippling penalty when his jackman entered the service stall too early. The crew member smartly ran back to pit wall and touched it to re-establish his position, leading NASCAR to make a no-call on the slip.

Keselowski was flagged for speeding on pit road, Hamlin was hampered by loose lug nuts during a stop, Truex had a loose wheel Harvick’s flat tire deflated his season.

Harvick was one point below the cutline when Elliott crossed the finish line with one car ahead of him to grab the required marker. But that one car was Kyle Busch — Hamlin’s teammate at Joe Gibbs Racing — and Busch wasn’t going to make it easy.

Harvick tried to knock Busch out of his way in a failed desperate effort. Both cars spun and Harvick missed making the final four by a single point.

“I tried to run into the door of the 18 as a last-ditch effort, trying to gain a point,” Harvick said. “We fought for everything, just came up short.”

Elliott, Keselowski and Hamlin will race Joey Logano, who had already clinched his berth, in next week’s finale at Phoenix. It’s a matchup of a pair of Fords from Team Penske against Hamlin’s Toyota and Elliott, the first Hendrick Motorsports and Chevrolet driver to make the finale since Jimmie Johnson won his seventh and final title in 2016.

Hamlin, a seven-time winner this season who went race-for-race with Harvick all year, lamented not getting a shot at his rival in Phoenix.

“I feel bad for Kevin, they probably deserve better than that,” Hamlin said. “Everything you do for eight innings doesn’t matter if you don’t have a good ninth inning.”

Harvick was eliminated along with Alex Bowman, Kurt Busch and Martin Truex Jr., who battled for the win until a late loose wheel ended his shot.