In qualifying for the Indianapolis 500, Ryan Hunter-Reay could manage no better than 19th-fastest in the 33-car field, which left him puzzled.

“It's a head-scratcher,” Hunter-Reay said at the time. “But the race is the only thing that counts.”

Hunter-Reay proved his point Sunday, winning his first Indy 500 after a thrilling duel with Helio Castroneves that ended with the second-closest finish in the history of the century-old race.

Hunter-Reay also became the first American driver to win the Indy 500 since Sam Hornish Jr. edged Marco Andretti in 2006 in what had been the second-closest finish.

“It's a dream come true,” Hunter-Reay, the 2012 Verizon IndyCar Series champion, said after taking the winner's traditional drink of milk in Victory Lane. “I'm a proud American boy, that's for sure.”

The Floridian's margin of victory over Castroneves was 0.060 of a second, or less than a car length. The closest finish ever was Al Unser Jr.'s win of 0.043 of a second over Scott Goodyear in 1992.

Marco Andretti and Carlos Munoz — Hunter-Reay's teammates on the Andretti Autosport team — finished third and fourth, respectively. Juan Pablo Montoya, making his first Indy 500 start since he won the race in his only previous attempt in 2000, was fifth.

And NASCAR driver Kurt Busch, in his first Indy 500, finished sixth in an Andretti Autosport car.

Busch completed “the double” Sunday: racing at Indy and then rushing to Charlotte (N.C.) Motor Speedway to drive in the NASCAR Coca-Cola 600 on Sunday night. (Busch finished 40th after blowing an engine on Lap 272).

Hunter-Reay had one of the strongest cars all day at Indianapolis Motor Speedway; he led a race-high 56 of the event's 200 laps.

But after the final restart with six laps left, Hunter-Reay and Castroneves swapped the lead in their yellow cars until Hunter-Reay retook it as they started the final lap.

Hunter-Reay at one point made a daring move on the inside where, as he put it, he even “cut a little [infield] grass” as he swept past Castroneves.

“I think that caught Helio completely off guard,” team owner Michael Andretti said.

As the crowd of more than 200,000 roared on a warm, sunny day, Castroneves — the Brazilian looking to become the fourth driver to win the Indy 500 four times — looked high and low in hopes of passing Hunter-Reay.

Castroneves tried one last time as they raced down the front straightaway toward the checkered flag, but he came up short.

“I tried, man, trust me,” Castroneves said. “It's frustrating to be so close. Unfortunately it wasn't our day.”

The final restart was set up by Townsend Bell's crash into the Turn 2 wall with 10 laps left.

Officials stopped the race with a red flag to repair the wall and clean up the debris left from Bell's mangled car.

A few laps earlier, Bell narrowly missed another big crash when he was three-wide with pole-sitter Ed Carpenter and James Hinchcliffe, with all three battling for second place.

As the trio went through Turn 1, Carpenter and Hinchcliffe collided and both crashed into the wall.

Carpenter, an Indianapolis native still looking for his first Indy 500 win, blamed Hinchcliffe for creating the risky situation. “I just didn't think he used his head right then,” Carpenter said. “It wrecked both of our races.”

Hinchcliffe said it was “100% not Ed's fault,” but Hinchcliffe added that he thought Bell would pull back to avoid the three-wide scenario. “I honestly don't think Townsend knew we were three wide,” Hinchcliffe said.

Other contenders had various problems, including 2008 Indy 500 winner Scott Dixon, who spun and crashed on Lap 168 while running fourth.

Castroneves' teammate Will Power also was running in the top 10 until he was penalized for speeding on pit road. That dropped him to 19th, but he rebounded to finish eighth.