McLaren driver Heikki Kovalainen won his first Formula One race Sunday after an engine problem forced Felipe Massa out of the Hungarian Grand Prix with three laps to go.

Massa overtook Kovalainen and pole sitter Lewis Hamilton at the start and was heading for his fourth win of the season after Hamilton dropped out of contention with a tire puncture. But the Brazilian's Ferrari engine overheated toward the end and Kovalainen took an 11-second victory over Timo Glock of Toyota.

"Of course I feel a little bit sorry for Felipe. I know how he feels with what happened to him today; I've had similar moments to him this year," said Kovalainen, who became the 100th driver to win a Formula One race.

Kovalainen _ greeted by chants of "Heikki" from the large Finnish contingent in the stands _ had narrowed Massa's lead to under six seconds before the Brazilian's engine blew up and ruined his chance of taking the lead in F1's standings for the second time this season.

"I just tried to put pressure on Massa hoping something would happen," Kovalainen said. "It worked out for me. I'm very, very glad to secure the victory."

Massa would have taken a three-point lead in the overall standings with a win, but instead slipped to eight behind Hamilton.

"It happened completely without warning, without giving the slightest indication," he said. "I am very frustrated at the moment because we had a great car and we had done everything perfectly until a few kilometers from the finish."

Ferrari's Kimi Raikkonen recovered from qualifying sixth to finish third ahead of Renault's Fernando Alonso and give the Italian team some needed points.

"We had the speed in the race. (It's qualifying) where we must sort it out," said Raikkonen, the defending world champion. "We need to get something sorted. My car is fast and we need to just get in the front to use it."

Hamilton, who won from pole here last year, came in fifth for McLaren and stretched his lead over Raikkonen in the overall standings to five points. McLaren overtook BMW Sauber to sit second in the constructors' standings _ 11 points behind Ferrari.

Kovalainen's first win in his 28 starts allowed Hamilton, coming off two dramatic victories at the British and German GPs, to stay atop F1's standings _ and eight points ahead of Massa, whose confident start left the McLaren drivers stranded.

Kovalainen said this week that he wouldn't help Hamilton even with his British teammate leading the title challenge, and that showed in his limp start that allowed Massa to pass easily on the outside.

Massa and Hamilton raced side-by-side into the first turn _ Massa even locking up his brakes at one point _ before the Brazilian stuck to his position to pull ahead and nudge out Hamilton around the second corner.

The two were out front on their own. Massa and Hamilton pitted within a lap of each other with Massa enjoying a three-second edge after the first round of stops at the 113-degree track.

Massa's lead was around three seconds as he edged Hamilton over the final two sectors of the twisting circuit before Hamilton's puncture left the race Massa's to lose. Hamilton had most of the 2.722-mile circuit to navigate before a tire change and re-emerged 10th.

"I feel I could have had a go at passing him, but the damaged tire halted my progress," Hamilton said. "I don't yet know what happened. But at least I scored four points and maintained my lead in the championship, so this result is not too bad for me."

Kovalainen, who will partner with Hamilton again in 2009, moved to within 7.5 seconds with laps running down on the 70-lap race.

"When I saw the car on fire on the straight, the smoke, I thought it could be Felipe but couldn't believe it," the Finn said. "I was able to bring it home."

Glock secured his first podium after overtaking BMW Sauber's Robert Kubica at the start and then holding off Raikkonen, who had pulled within five seconds of the German driver.

"I just tried not to do any mistakes and stay in front of him," said the 26-year-old Glock, who rebounded from a violent crash at the German GP. "I didn't expect the podium. ... It's just the perfect weekend."

Renault's Nelson Piquet Jr. followed up a podium at Hockenheim with a sixth-place finish ahead of Toyota's Jarno Trulli.

Kubica, with at least 25,000 Polish fans cheering him on, crossed the finish line in eighth for his worst placing of the season to trail Hamilton by 13 points.

Sebastian Vettel retired after 22 laps when his engine overheated, while the Toro Rosso pit crew was forced to put out flash fires on teammate Sebastien Bourdais' car at both of the Frenchman's pit stops.

Bourdais finished 18th after pitting a third time to wipe off excess foam on his visor from the fire extinguisher.

The teams and drivers have three weeks before the next race on Aug. 24 _ the inaugural Valencia GP.