WATKINS GLEN, N.Y. — AJ Allmendinger’s journey is almost complete.

With a new contract, sponsor extensions and a solid one-car team at JTG Daugherty Racing, Allmendinger became a winner in Sprint Cup for the first time on a somber Sunday, outdueling Marcos Ambrose in the final two laps at Watkins Glen International.

“I dreamed about this moment and I’m not going to forget it,” said Allmendinger, making his 213th Cup start. “It’s just a dream come true.”

The day began on a solemn note when three-time Cup champion Tony Stewart pulled out of the race 12 hours after he struck and killed 20-year-old sprint car driver Kevin Ward Jr..

Allmendinger offered his condolences to the Ward family after he won, saying, “We’re a community here, we’re thinking about you.”

Regan Smith drove Stewart’s car and finished 37th after having to start from the back of the 43-car field and getting caught in a late accident.

It was the second straight time Stewart missed the race at The Glen, where he has a NASCAR-record five victories. Last year, he broke his leg in a sprint car accident in Iowa days before the Cup race and missed the rest of the season.

Allmendinger’s life changed two years ago in the hours before the July race at Daytona International Speedway. NASCAR officials had just kicked him out of the track, suspending him indefinitely for failing a drug test.

The failed drug test sidelined him for more than three months and cost him his job with Penske Racing. It also spurred much soul searching, and after a handful of one-off Cup rides he eventually landed a full-time Cup ride last August with JTG Daugherty Racing.

To break through the way Allmendinger did only added to the lore of this race, which has been decided four straight times by fender-banging dashes to the checkered flag. Ambrose won two of those and Kyle Busch the other.

An expert road racer from his days in open-wheel, Allmendinger beat the best in Ambrose, who has been dominant in NASCAR’s top two series at The Glen, also winning four straight Nationwide events.

Ambrose was going for a weekend sweep after capturing the Zippo 200 on Saturday.

“I’m thrilled for AJ,” said Ambrose, who drove for JTG Daugherty before Allmendinger. The victory made JTG Daugherty Racing eligible for the Chase for the Sprint Cup title, and Allmendinger isn’t planning on stopping there.

Allmendinger held off Ambrose through the first two turns on the final restart and opened a lead after both cars bumped and won going away.

“I try to get better every day. I’m still not where I want to be,” Allmendinger said. “I wouldn’t want to go back and change the process. I wouldn’t change a thing about this.”

Allmendinger gained the lead on Lap 64 after pit stops, with Kurt Busch and Ambrose close behind.

Ambrose outbraked Busch into Turn 1 for second two laps later and set his sights on Allmendinger, who had a 2-second lead that was wiped out by the late stoppages.

Jeff Gordon started from the pole and led the first 29 laps. But his engine died on lap 50.