INDIANAPOLIS (AP) — This was a race with the weather. Which would come first, the rain or the end of the Indy 500?

Dario Franchitti gambled on the rain and won Sunday, another bittersweet day for the Andretti family at America’s richest race.

The Scotsman, one of five Andretti Green Racing drivers in the field, took the lead when the leaders pitted one last time for fuel despite darkening skies, and then drove slowly to the checkered flag in a downpour when the race was stopped after 166 laps, or 415 of the scheduled 500 miles.

“Our roll of the dice proved to be the lucky one,” a jubilant Franchitti said. “I made a couple of good restarts and the rain came.”

None too soon by Franchitti’s reckoning.

As the dark clouds drew ever closer, crew chief John Anderson told him on the radio, “The rain’s eight blocks away.”

“Come on!” Franchitti said. “I was just hoping it would start soon.”

The race had already been interrupted by rain for three hours shortly after the midway point, and Franchitti won it under a caution light brought out when teammate Marco Andretti crashed three laps from the premature finish.

Andretti, who lost this race last year as a 19-year-old rookie when Sam Hornish Jr. passed him on the final straightaway, had slipped into the pack and was trying hard to move back into contention when he tried to make a pass in traffic and came together with 2005 Indy winner Dan Wheldon on the back straightaway.

Andretti’s car veered hard into the outside wall, slid back across the track in traffic and flipped on its top after it hit the infield grass. It finally came to rest on its wheels and Andretti was able to climb out uninjured.

“I’m one lucky guy,” Marco said. “I’m so proud of Dario Franchitti.”

Franchitti made a victory lap of the 2.5-mile oval in the heavy rain as actress wife Ashley Judd, soaking wet in a summer dress, climbed the pit wall and dashed toward the victory celebration.

Once Franchitti got out of his car, he was mobbed, hugged and kissed by teammates Tony Kanaan, his best friend, Danica Patrick and Michael Andretti.

“I can’t believe it. It’s the Indy 500!” Franchitti said. “To be a member of this club is fantastic. I kind of have half of an idea of what it means to win this race. I’m so happy.”

Franchitti’s average speed was 151.774 mph, far from the record 185.81 mph by Arie Luyendyk in 1990.

Scott Dixon was second, followed by Helio Castroneves and Sam Hornish Jr. The rest of the top 10 were Ryan Briscoe, Scott Sharp, Tomas Scheckter, Patrick, Davey Hamilton and Vitor Meira.

It was Andretti Green’s second victory in three years, but that's about all the good luck the Andrettis have had at Indy since Mario Andretti, Marco’s grandfather and Michael’s father, won in 1969.

Kanaan, had appeared in control when rain poured down the first time after 113 laps, just four laps after he took the lead with a pass on Andretti.