Ryan Blaney won the VisitMyrtleBeach.com 300 XFINITY Series race at New Hampshire Motor Speedway on Saturday night, beating Ty Dillon to the front on a green-white-checkered finish to take the checkered flag.

It was Blaney's fourth career win in his 41st series start, and he had to overcome a bad restart on the next-to-last restart to do it.

"The only way to atone for it was to win the race," Blaney said.

More from FoxSports

He did that by getting out in front of Dillon on the very next -- and last -- restart of the race, then held Dillon off for the remainder of the G-W-C finish.

It was a long night that included a red-flag period that lasted 18 minutes, 26 seconds when the track needed cleaned up after an incident involving the cars of Brennan Poole and Ben Rhodes.

There were numerous other wrecks and yellow caution flags, including one with 14 to go that appeared to be set in motion when the No. 2 car of Brian Scott touched the No. 98 of Ryan Truex, sending Truex spinning. The No. 4 car of Ross Chastain then plowed into Truex, setting up what turned out to be the next-to-last restart with nine laps to go.

Leader Blaney had a poor restart, however, and quickly was passed not only by Ty Dillon but also Matt Tifft and Regan Smith. Blaney battled back to second before the next caution came out for a spin by Jeremy Clements with five laps remaining, bringing out the record-tying 10th caution of the night.

That set up the green-white-checkered finish and gave Blaney a chance to atone for his earlier mishap. He started on the inside of the front row next to leader Ty Dillon and beat Dillon on the restart this time, using some assistance from Smith behind to surge ahead in his No. 22 Team Penske Ford.

"It hurts to lose it like that," Dillon said. "I got a good launch on that final restart, and I saw the 22 (of Blaney) getting pop, pop, popped -- bumped by the 7 (of Smith). The 20 (of Tifft) gave me a bump like that on the restart before, so I knew he'd be tough to hold off. And once you get into clean air, you can be Superman for three laps."

It was quite a night for 19-year-old Tifft, who was making his series debut in a Joe Gibbs Racing car. He was second late in the race and started third on the next-to-last restart before eventually finishing 10th.