Red Bull driver Daniel Ricciardo captured the chequered flag for the second time this season at the end of an astonishing Hungarian Grand Prix.

Rain, crashes and safety cars made for a stunning race, aiding the previously forlorn Lewis Hamilton following his fire in qualifying on Saturday into another podium finish for the second successive Sunday from a seemingly hopeless position.

Ferrari's Fernando Alonso secured second for his best result for 10 months, with Hamilton hanging on to third by the skin of his teeth ahead of his charging Mercedes team-mate Nico Rosberg.

Fearing a 30-point deficit to Rosberg going into the summer break in the wake of the fire that resulted in him starting from the pit lane to the German's pole, Hamilton is now only 11 points adrift with eight races to run.

Come the start of the race, and with 20 cars between himself and Rosberg, Hamilton could not have envisaged his situation going from bad to worse within seconds, but that is exactly what unfolded.

At the back of the pack, and with cold brakes on cold tyres, Hamilton spun into turn two, damaging the right corner of his front wing.

A penny for Hamilton's thoughts at that stage as he crossed the line at the end of lap one 21 seconds behind Rosberg, who had made a clean getaway.

Just 40 minutes later, however, the gap was down to one second and with only one car between them, with Hamilton fifth and Rosberg third.

What unfolded in between was a remarkable series of events, sparked by a damp track as a downpour 50 minutes before the start had thrown all strategies out of the window.

After eight laps, and with Hamilton having scythed his way up to 13th, Caterham's Marcus Ericsson smashed into a barrier at turn eight, bringing out the safety car.

Just when it was poised to return to the pits, Lotus' Romain Grosjean also spun into a wall, ensuring it remained out for a little while longer.

With pit stops unfolding at the start of the safety car period, the shake up come the end of 15 laps meant Ricciardo led from Williams' Felipe Massa and Alonso, with Rosberg fifth, Sebastian Vettel sixth in his Red Bull and Hamilton seventh.

Eight laps later Sergio Perez, who had tangled with Force India team-mate Nico Hulkenberg on lap 17 that led to the German's retirement, ran wide at the final turn, lost control and slammed into a concrete wall along the start-finish straight, scattering debris across the track.

For the second time safety-car driver Bernd Maylander slowed down the field for a further four laps, at the start of which Ricciardo and Massa pitted.

The further reshuffled handed Alonso the lead, with Toro Rosso's Jean-Eric Vergne second, followed by Rosberg, Vettel and Hamilton.

It was an astonishing turnaround, and at that stage there were still 46 laps remaining.

Come the end of lap 38, as further stops unfolded, Hamilton led the race for a lap, but only a lap, as his own stop followed, dropping him to fifth.

It was not too long before Hamilton was up to third, with Rosberg fourth, but on the quicker soft tyre compared to his team-mate who was running to the end on the slightly slower medium Pirelli rubber.

Come lap 51 Rosberg asked for the team to call on Hamilton to move aside, but there was no response from the Briton.

Two laps later and Rosberg demanded of his team 'Why is he not letting me through?', with the reply 'He has had the message Nico, he has had the message.'

Rosberg, however, never got close enough to Hamilton to suggest he was looking to pass, and the latter was seemingly within his rights not to let the former by given the championship standings.

Given he was chasing the victory, and bearing in mind the finale, it was the right call from Hamilton.

With leader Ricciardo pitting on lap 54 for fresh soft tyres, as Rosberg had two laps previously, that gave them both a run at the front two of Alonso and Hamilton.

With Alonso on wearing soft rubber, Hamilton on wearing mediums and Ricciardo on newer softs, the denouement was enthralling and for the final 10 laps they were line abreast.

Ricciardo finally made moves stick on Hamilton on lap 67 into turn three and then Alonso soon after into turn one on lap 68.

With Ricciardo away and clear, to add to his success in Canada in June, Rosberg then reeled in Alonso and Hamilton.

There was one move on Hamilton out of turn one, but the former held his nerve to claim a crucial third, as was the case last Sunday in Germany when he started from 20th after a brake-disc failure.

With his trademark beaming smile in evidence, a thrilled Ricciardo said of his win: "It feels as good as the first, it really does.

"The first safety car was to our advantage, but the second didn't help us, but we managed to pull it off in the end, and those last few laps were a lot of fun."

Despite missing out on Ferrari's first win for 25 races as the team ran the Spaniard to the end for over 30 laps on soft tyres, a happy Alonso said: "I'm extremely satisifed.

"It's been a tough weekend, a tough season, so to get a podium was a nice surprise.

"We gambled to get the victory, and we came close, but I'm extremely happy.

"We need some crazy races this year to get some podiums, and this was an opportunity which we took."

As for Hamilton, he said: "It's been a pretty crazy weekend.

"A big thank you to the team for the pit stops and strategy

"The car is fantastic - when it's going - but there are a lot of strengths."

Asked whether it was one of his finest ever drives, he smiled and replied: "I don't think so."