Daniel Ricciardo took a stunning victory in a thrilling Hungarian Grand Prix as Lewis Hamilton beat team-mate Nico Rosberg despite starting from the pit lane.
In a race affected by rain and two safety car periods, Alonso was holding off Hamilton and Ricciardo for numerous laps but pulled an exquisite on Hamilton before passing the Ferrari in to Turn 1 to take his second win of the season.
Alonso somehow finished second having completed 32 laps on soft tyres, while Hamilton held off Rosberg to the line to take third having started from the pit lane and spun on the opening lap.
Rosberg will wonder how he dropped from pole position and an early commanding lead to finish behind his team-mate, but tensions seem set to rise at Mercedes as Hamilton ignored calls to allow Rosberg through and robustly defended on the final lap.
Ricciardo’s drive was superb, as were those by Alonso and Hamilton as any one of the three could have taken victory in the closing stages.
Fifth was Felipe Massa after a solid race, holding off Kimi Raikkonen who also delivered an impressive recovery having started in 16th place.
Sebastian Vettel managed to finish seventh despite a high-speed spin out of the final corner which looked certain to end his race. Valtteri Bottas, Jean-Eric Vergne and Jenson Button completed the top ten.
A huge downpour in the hour before the race left the track wet and drivers starting on intermediate tyres. After Daniil Kvyat failed to get off the grid for the formation lap, Rosberg led in to Turn 1 from Bottas and Alonso, although Vettel soon jumped the Ferrari in to third place.
Hamilton had emerged from the pit lane behind the pack and spun under braking for Turn 2, making light contact with the wall but being able to continue.
While Rosberg had built up a substantial lead, the race was turned on its head when Marcus Ericsson crashed head-on in to the barriers at Turn 3, causing the first safety car period. With the track drying, everyone piled in to the pits but the four leaders were already past the pit exit and had to wait for an extra lap, dropping them in to the pack.
The two McLaren drivers opted for intermediate tyres while the rest of the field chose slicks and Romain Grosjean highlighted just how tricky conditions were by crashing behind the safety car while warming his tyres.
On the restart, Button jumped Ricciardo as the intermediates offered more grip, while Magnussen was soon up to fourth behind Vergne but ahead of Rosberg. As the inters went off, the McLarens were very slow but a failed attempt to pass cost Rosberg more positions.
With the two McLarens pitting, Ricciardo was released in to the lead with Massa in second and Alonso catching the pair in third place. Vergne held off Rosberg – who had Vettel and Hamilton right behind – until another safety car period when Sergio Perez lost control exiting the final corner and hit the wall on the inside of the track.
Ricciardo and Massa pit under the safety car, leaving Alonso in the lead. With Vergne continuing to hold off Rosberg after the restart, Rosberg pit on lap 32 for soft tyres and at the same time, Vettel had a replica of Perez’s spin but brilliantly kept the car out of the wall.
Hamilton had been released from behind Vettel and soon passed Vergne with a sublime move around the outside of Turn 4 having had two wheels on the grass on entry, going on to open up enough of a gap to pit and rejoin ahead of Rosberg.
With Alonso having also pit on lap 38 for soft tyres, Hamilton was on the mediums and found himself behind the Ferrari but ahead of his team-mate. Mercedes told Hamilton on the radio to allow Rosberg – on softs – to pass, but with the championship leader rarely within a second Hamilton didn’t do so.
Following those pit stops, Ricciardo had a ten second lead and the top four all circulated at similar speed. With 16 laps to go, Ricciardo pit for more soft tyres and emerged in fourth ahead of the two Williams cars.
Having been unable to pass Hamilton, Rosberg pit as well and dropped behind Bottas, Massa and Raikkonen which appeared to end his hopes. However, Bottas soon pit and Rosberg quickly dispatched the other two in order to chase the leaders.
With a gap of over 20s to close in the final nine laps, Rosberg was helped by a defensive Alonso holding of Hamilton and Ricciardo. The Red Bull was the only car on fresh tyres and just as Rosberg was closing in, Ricciardo overtook Hamilton around the outside of Turn 2, drifting the car on exit to get to the Turn 3 apex ahead.
Following such a stunning move, Ricciardo dived up the inside of Alonso from a long way back in to Turn 1 with three laps remaining to secure his second win of the year.
Rosberg had caught Alonso and Hamilton with two laps to go but found his team-mate too difficult to pass and had to settle for third.
The result sees Hamilton cut Rosberg’s championship lead to 11 points, while Ricciardo in third is now 71 points off Rosberg.