INDIANAPOLIS (AP) – Kasey Kahne survived a crash-marred Brickyard 400 on Sunday for his first NASCAR Cup victory in three years.

The Hendrick Motorsports driver won under caution in the race that took more than six hours to complete, finally finishing in fading light after 167 laps and double overtime.

Brad Keselowski finished second.

It was a wild day at Indianapolis Motor Speedway with Kyle Busch and Martin Truex Jr. – driving the two fastest cars – going out in a crash with 49 laps to go.

That was only a prelude the nutty final 20 laps that included five crashes, two of which brought out red flags.

Busch looked as if he would make history as the first driver to win three consecutive Brickyards when he led the first 71 laps – and 87 overall. But when Truex’s car slid up the track, both cars hit the wall.

That opened the door for Kahne, who had struggled all season. And as the crashes happened behind, Kahne overcame muscle cramps to hold on for his 18th career victory and first since Atlanta in 2014.