(CNN) -- Finland's Heikki Kovalainen took advantage of a cruel piece of luck for Ferrari's Felipe Massa to claim his maiden Formula One victory in the Hungarian Grand Prix on Sunday.
Heikki Kovalainen celebrates his unexpected victory at the Hungarian Grand Prix, his first in F1.
Massa looked certain to win when his engine blew with three of the 70-lap race remaining.
Kovalainen, 26, won from Toyota's Timo Glock with Ferrari's Kimi Raikkonen in third place.
Brazil's Massa had been set to take over the world championship lead from Kovalainen's McLaren teammate Lewis Hamilton, who suffered a puncture with 29 laps remaining and eventually finished fifth.
Hamilton has extended his title lead to five points ahead of world champion Raikkonen. Massa is now in third place, eight points adrift.
"I think I salvaged the best of the worse I guess," Hamilton told ITV Sport. "What can I do when you have a puncture, last year we lost the title on punctures."
Massa charged off the start to overtake polesitter Hamilton and Kovalainen, who had occupied the front row.
Britain's Hamilton, who gone into the race off the back of wins at Silverstone and Hockenheim, was in second place behind Massa, but failing to make a real impression, when he punctured.
Two-time world champion Fernando Alonso finished fourth for Renault, just ahead of Hamilton, who had to nurse home his soft tires on the testing Hungaroring circuit after being forced to run an extended third stint.
A thrilled Kovalainen said: "I'm very happy. "There have been various incidents this season that have happened when I've been in a position to fight for a victory.
"At the end I tried to put pressure on Massa and hoped something would happen, and it worked out that way."
Massa would have gone three points clear at the top if he had won, but instead was left to reflect on his misfortune.
"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."
Germany's Glock, who impressed to claim his first podium, was understandably delighted.
"It's just unbelievable," he said. "I couldn't believe it when I saw Felipe's engine go and I was P2, so this is remarkable after the race in Hockenheim and the big crash. To get a podium is just a perfect weekend."
Raikkonen was pleased with his efforts after qualifying only sixth on Saturday, but urged his team to make further improvements.
"We had the speed in the race. (It's qualifying) where we must sort it out," the Finn said. "We need to get something sorted. My car is fast and we need to just get in the front to use it."