Kovalainen inherits victory
Hamilton retains Championship lead despite puncture
McLaren Mercedes driver Heikki Kovalainen has won the Hungarian Grand Prix after Felipe Massa suffered an engine failure late in the race.
Ferrari driver Massa had looked all set to score his fourth victory of the season after taking the lead from polesitter Lewis Hamilton at the start.
He also appeared positioned to retake the lead in the World Championship after Hamilton suffered a puncture on lap 40.
But, just three laps from the chequered flag, Massa pulled off the start-finish straight, a plume of smoke trailing his car.
On a weekend which saw McLaren extend his contract for another season, Kovalainen thus took the first victory of his Formula One career.
Toyota's Timo Glock came back from the serious shunt he suffered at Hockenheim to finish a fine second second ahead of World Champion Kimi Raikkonen.
Fernando Alonso finished fourth for Renault, with Hamilton fifth ahead of Nelson Piquet Jr.
Toyota's Jarno Trulli finished seventh ahead of BMW Sauber's Robert Kubica.
Hamilton now has a five-point lead in the championship, but from Raikkonen, with Massa a further three points adrift.
Up until lap 67 of the race it had appeared that Hamilton would be heading into F1's summer break trailing Massa in the championship.
Such an eventuality would certainly have gone against the recent trend seen in the sport - Hamilton appearing a picture of confidence this weekend as he chased a third straight win.
But, possibly still smarting at the manner in which he had been muscled out of second place by Hamilton late in the German Grand Prix a fortnight ago, Massa had clearly read a different script.
Starting third on the grid, he scythed past Kovalainen at the lights and then, bearing down on Hamilton, the Ferrari aggressively locked its brakes heading into turn one.
The red and silver cars duelled side-by-side through the corner, with Massa standing his ground and passing Hamilton around the outside for the lead.
The Ferrari then edged out a 2.8-second lead by lap 10, with Hamilton in turn 4.9 seconds ahead of his team-mate.
Massa was 3.8 seconds ahead by the time he pitted at the end of lap 18, rejoining in fourth. Hamilton assumed the lead but only for a single lap, the McLaren pitting before rejoining in sixth place.
Kovalainen also led for just the one lap before pitting, with Massa resuming control on lap 22 ahead of Alonso and Raikkonen.
The World Champions then made their opening stops in tandem - the Spaniard just getting the drop in the pitlane.
Massa now led Hamilton by 3.1s, with Kovalainen back up to third place after Piquet made his opening stop on lap 25. Glock was fourth, ahead of Alonso, Raikkonen, Piquet and Trulli.
McLaren's longer pit stop suggested Hamilton had taken on more fuel than his chief rival. He proceeded to try and keep himself within touching distance of the lighter Ferrari - the intention being for him to run several laps longer and get ahead at the second stops.
Although the five-second lead Massa held by lap 40 suggested both he and Ferrari had the pace to stay in front, what ultimately sealed Hamilton's fate was the left front puncture he then suffered.
His second stop was therefore brought forward and, fuelled to the end of the race, Hamilton rejoined in 10th place ahead of Red Bull's David Coulthard.
Massa therefore had the race in the bag, holding as he did a 23.6-second lead over Kovalainen. He made his second stop on lap 44 and rejoined in second place ahead of Glock.
Kovalainen made his second stop on lap 47, with Massa now leading Alonso and Raikkonen. The leading Renault pitted on lap 50, with the reigning World Champion jumping ahead after stopping one lap later.
Massa by now led Kovalainen by 15.4 seconds, with Glock another 8.2 seconds behind in third. Hamilton had climbed to eighth and then moved up two more places after Trulli and Piquet made their second stops.
The closing laps saw Raikkonen - for the first time during the course of the weekend - really finding his groove as he closed in on Glock, the Finn setting the fastest lap of the race nine laps from the finish with a 1:21.195s.
Then came the scenes which encapsulated the summer Ferrari have thus far endured.
As Massa trudged back to the pits, Kovalainen assumed the lead and duly took the chequered flag seven seconds ahead Glock, with Raikkonen third after Massa's retirement prompted him to back off.
Hungarian Grand Prix, result:
1. Heikki Kovalainen (Finland) McLaren 1hr 37min 27.067secs
2. Timo Glock (Germany) Toyota +00:11.061
3. Kimi Raikkonen (Finland) Ferrari 00:16.856
4. Fernando Alonso (Spain) Renault 00:21.614
5. Lewis Hamilton (Britain) McLaren 00:23.048
6. Nelson Piquet (Brazil) Renault 00:32.298
7. Jarno Trulli (Italy) Toyota 00:36.449
8. Robert Kubica (Poland) BMW Sauber 00:48.321
9. Mark Webber (Australia) RedBull - Renault 00:58.834
10. Nick Heidfeld (Germany) BMW Sauber 01:07.709
11. David Coulthard (Britain) RedBull - Renault 01:10.407
12. Jenson Button (Britain) Honda 1 lap
13. Kazuki Nakajima (Japan) Williams - Toyota 1 lap
14. Nico Rosberg (Germany) Williams - Toyota 1 lap
15. Giancarlo Fisichella (Italy) Force India - Ferrari 1 lap
16. Rubens Barrichello (Brazil) Honda 2 laps
17. Felipe Massa (Brazil) Ferrari 3 laps
18. Sebastien Bourdais (France) Toro Rosso - Ferrari 3 laps
r. Adrian Sutil (Germany) Force India - Ferrari 8 laps
r. Sebastian Vettel (Germany) Toro Rosso - Ferrari 48 laps
(rank: r = retired, nc = not classified)
Fastest Lap: Kimi Raikkonen, 1:21.195, lap 61.