AVONDALE, Ariz. — Cole Custer pulled away from Justin Allgaier during a two-lap overtime shootout to win his first NASCAR Xfinity Series championship Saturday night at Phoenix Raceway.

It was an exhilarating finish, with Custer, Allgaier and John Hunter Nemechek three-wide on the next-to-last lap, with Allgaier’s JR Motorsports Chevrolet finding some room in between the other two cars. But Custer — who went to the inside — pulled away while the others battled for position.

“I can’t believe we won that thing,” Custer said.

It was a sweet moment for the 25-year-old Custer, who had a Cup ride for the Ford Stewart-Haas Racing team the past three seasons before being demoted this year to the Xfinity Series. It’s also a bright spot in a tough season for the Stewart-Haas racing, which hasn’t won a race in the Cup Series this season.

The four championship drivers were in the top four spots for the final restart, which was brought on after Anthony Alfredo spun out with five laps remaining.

Custer — who was the Xfinity Series runner-up in both 2018 and 2019 — went low as Nemechek stayed high, with Allgaier making a brief run up the middle that brought the crowd to its feet.

Allgaier finished third, Sam Mayer ended up fifth and Nemechek fell to 28th after hitting the wall on the final lap.

“The restart was fantastic — we did everything right,” Allgaier said. “I’m going to replay this one in my head a couple times.”

Allgaier put himself in a tough situation on Saturday’s second lap when he tried to go low on the apron, bumping against Nemechek before spinning out and falling back to 36th. But the 37-year-old made up ground in a hurry, moving all the way up to third after his pit stop following the first stage.

Allgaier won four times this season, earning a spot in the championship round by beating Sheldon Creed in a door-to-door finish to win at Martinsville last week.

Nemechek, son of former Xfinity Series champion Joe Nemechek, had an ill-fated Cup Series debut for Front Row Motorsports in 2020. He was in a tough situation during NASCAR’s COVID-19 “bubble” season, his only seat time coming during races because there was no practice or qualifying.

Nemechek will be back in the Cup Series next year with Legacy Motor Club, which is owned by Jimmie Johnson.

The 20-year-old Mayer has had a quick rise in NASCAR, starting with the Trucks Series in 2019. He won in Charlotte and Homestead to make the playoffs for the second straight year. Even after falling short of a championship, he was pleased with the team’s effort.

Mayer’s fifth-place finish was his best in Phoenix.

“That’s probably the most fun I’ve had in a race car in a long time,” Mayer said.