Sebastian Vettel dedicated his victory to Jules Bianchi after winning a thrilling Hungarian Grand Prix.
In a race which had it all, the Ferrari driver finished ahead of Daniil Kvyat with the Russian's Red Bull team-mate Daniel Ricciardo completing the podium.
Pole-sitter Lewis Hamilton endured an error-prone race as he crossed the line in sixth.
SIGN UP NOW
Want to become a GMS writer? Sign up now and submit a 250 word test article: http://gms.to/haveyoursay4
But there was some joy for the Briton after his Mercedes team-mate and rival for this year's championship Nico Rosberg could manage only eighth following a collision with Ricciardo in the closing stages.
The Formula One community arrived here in Budapest under a cloud following Bianchi's death last Friday from the injuries he suffered during last season's Japanese Grand Prix.
But his contemporaries vowed to race on in the Frenchman's honour and they delivered one of the finest races in recent seasons.
Hamilton had been expected to cruise to a record fifth victory here in Budapest, but the world champion made a catalogue of errors and was fortunate that he finished sixth. It could, and probably should, have been a lot worse.
Both Hamilton and Rosberg suffered poor getaways at the British Grand Prix, and the Mercedes pair were again painfully slow off the start-line here.
Vettel, who started from third, went toe-to-toe with Hamilton on the 180mph run down to turn one before taking the lead and he never looked back.
"This victory is for Jules," Vettel said.
"We know this has been an incredibly tough week. It has been difficult and this one is for him."
Hamilton, baulked by Vettel at the opening turn, then lost out to Rosberg and Kimi Raikkonen. The Finn, battling to save his Formula One career, dived underneath Rosberg at turn two to move up to second.
Hamilton appeared flustered by yet another poor start and he attempted to pass Rosberg at the chicane, but the move failed. He stepped on to the grass and then ran across the gravel before rejoining the track in 10th.
The Briton was angry with his team-mate's tactics.
"Nico crossed over my line there, pushed me wide. You're only supposed to move once," he said over the radio.
With Vettel and Raikkonen pulling away from Rosberg at the front of the field, it was Hamilton who would provide the entertainment.
On a track where it is notoriously difficult to overtake, Hamilton passed the Williams of Felipe Massa on lap 10 to move up to ninth. He began his pursuit of Sergio Perez and three laps later he had passed the Mexican.
Where he had overtaken Massa around the outside at turn one, Hamilton dived underneath Perez at the same spot. Ahead of him, Nico Hulkenberg, Valtteri Bottas and Kvyat all pitted to promote Hamilton to fifth by the end of lap 16.
In clear air, Hamilton promptly set the fastest lap of the race and despite a sluggish pit-stop at the end of lap 19, he emerged alongside Bottas before seeing off the Williams driver on the run down to turn two. It left him a net fifth with Ricciardo up next.
Hamilton, on the faster option tyre, struggled to find a way past the Australian though, even running wide at turn 11 in his desperate bid to move ahead of the Red Bull.
But on lap 29, Hamilton made his decisive move. He deployed DRS and powered past Ricciardo on the main straight. With Vettel leading Raikkonen and Rosberg, Hamilton set about catching his Mercedes team-mate.
The gap had been 16 seconds, but Hamilton was just seven adrift of his team-mate when the race was thrown the most spectacular of curveballs.
Nico Hulkenberg's front wing shattered at close to 200mph and the Force India driver ploughed into the tyre wall. Fortunately, he walked away unscathed, but with parts of carbon fibre littering the track the Virtual Safety Car, and then the Safety Car proper was deployed.
Vettel led from Raikkonen, now suffering from a power failure, with Rosberg in third and Hamilton fourth.
But when the safety car dived in on lap 48, a race already fuelled with drama took not one, but two incredible twists.
Hamilton was slow to get away, and with Ricciardo bidding to overtake the Briton at turn one, Hamilton lost control of his Mercedes under braking and hit the Red Bull sustaining damage to his front wing.
Further ahead, Rosberg easily negotiated the slowing Raikkonen to move up to second.
While Hamilton, now in sixth, tried to nurse his damaged Mercedes home he was left with no option other than to pit for a new front wing two laps later.
He emerged in 13th and to make matters worse he was then slapped with a drive-through penalty for causing the crash with Ricciardo.
"I'm really sorry, guys," a deflated Hamilton said to his team. His hopes of a points finish looked unlikely.
Back up front, Raikkonen, unable to continue, retired on lap 53, meaning it was now Vettel who led from Rosberg and Ricciardo. The top three were separated by less than two seconds with eight of the 69 laps remaining.
Ricciardo then sailed underneath Rosberg at turn one but as the German tried to take the position back he collided with the Red Bull driver.
Rosberg was left with a left-rear puncture and Ricciardo a damaged front wing. The pair hobbled back to the pit lane.
Ricciardo managed to re-join in third, but Rosberg was way down the order in 10th, now behind Hamilton - the Briton in seventh but ultimately passing Romain Grosjean for sixth.
Rosberg managed to salvage eighth, but lost ground to Hamilton in the title race. The gap is now 21 points heading into the summer break.
Max Verstappen, the 17-year-old rookie, finished an incredible fourth with Fernando Alonso in fifth for McLaren, Romain Grosjean seventh, Jenson Button ninth and Marcus Ericsson completing the top 10.