AJ Allmendinger took advantage of two frightening multi-car crashes, the leader getting spun out and a penalty — all in the final five laps — to win the Brickyard 200 on Sunday at Indianapolis Motor Speedway.

AJ Allmendinger, driver celebrates with his team on Indy's Yard of Bricks.

AJ Allmendinger, driver celebrates with his team on Indy's Yard of Bricks. (Stacy Revere/Getty Images)

Making only his second NASCAR Cup start of the season, the 39-year-old Allmendinger raced to his second career Cup victory and gave Kaulig Racing its first win in only the organization's seventh series start.

But the 0.929-second victory over Ryan Blaney in the first Cup race on the 14-turn, 2.439-mile road course was marred by two huge pileups that brought out red flags.

The first came with five laps to go, starting when pole-winning driver William Byron went over the curbing in the fifth turn and was sent off the course. Eight more drivers quickly followed him, immediately bringing out a yellow and eventually a red flag.

"It was so weird, I've never had that experience before," Byron said, saying he first noticed the problem when Kyle Larson went through the section just ahead of him. "I nailed something and tore it up."

Track workers, who had been tending to the chicane throughout the race, eventually removed it and towed it away as fans cheered. Even Indianapolis Motor Speedway President Doug Boles walked onto the track in a suit and tie, grabbed a broom and helped clean the area.

When the engines restarted, nobody was sure what to expect or how to navigate the altered turn. A few moments later, seven more cars crashed in the same spot and again the race was halted.

NASCAR officials did not immediately report any significant injuries.

Organizers made one modification to the track overnight — removing a "turtle" in the sixth turn that had caused some trouble during Saturday's doubleheader. But it was the fifth turn that became problematic Sunday.

Some wondered whether fatigue from three days of practice, qualifying and racing on the same course could have led to the deterioration of the curbing.

Drivers refused to speculate.

"I don't believe in luck but I feel like that was bad luck," Joey Logano said. "Wrong place, wrong time. I went around as a passenger, knowing what was going to happen."

It wasn’t just the crashes.

Denny Hamlin had the lead with two laps to go and appeared headed toward victory when Chase Briscoe’s second-place car went skittering through the grass between the first two turns. The two cars raced side-by-side briefly before Hamlin pulled slightly ahead heading into the 10th turn.

That's where Briscoe, who said he was unaware he had been penalized, spun out Hamlin.

"Just a lack of awareness," Hamlin said. "I just wanted him to race me for a lap. I don’t think he did it maliciously He’s not that kind of person. This just turned everything upside down."

Even before the crashes, though, this race looked more like short-track event.

CLICK HERE TO GET THE FOX NEWS APP

At one point, Brad Keselowski hit a concrete wall and pitted with the back part of his car dragging. At another, track workers pulled a 3-foot section of metal out from underneath curbing. Several cars used duct tape to keep parts together and while some drivers inadvertently drove off course, others were sent spinning. Following the big melee, there was damage up and down the stopped car line.

Somehow, though, Allmendinger made his way to the front.

"It was just survival of the fittest," he said. "We probably had an eighth to 15th place car. Those restarts were just insane."

Allmendinger also won a road-course race at Road America in 2013.

Larson took the points lead from Hamlin by finishing third, one day after winning the Knoxville Nationals. Hamlin wound up 23rd.

Tyler Reddick won the first two stages, gaining crucial points toward a playoff spot. He beat Richard Childress Racing teammate Austin Dillon to the yard of bricks both times with Dillon finishing third in the first stage and moving up one spot in the second.

UP NEXT

After back-to-back road races, the Cup circuit returns to an oval next Sunday at Michigan International Speedway.