A qualifying session that began with chaos ended with it, too, allowing Nico Rosberg to leapfrog Mercedes teammate Lewis Hamilton and take pole position for Sunday's Formula 1 Hungarian Grand Prix. Hamilton had looked set to extend his advantage in the final phase of a rain-disrupted qualifying session at the Hungaroring when yellow flags raised for Fernando Alonso's McLaren spinning off the track forced him to back off. Rosberg was behind Hamilton and appeared to slow only marginally allowing him to stay on the pace sufficiently to complete his quick lap as time expire and snatch the fastest time from under Hamilton's nose.

More than three hours after qualifying concluded, Rosberg's pole was called in jeopardy when stewards initiated an investigation into whether he had slowed sufficiently for the waved yellow flags. Starting behind the Mercedes on on Sunday will be the two Red Bulls, with Daniel Ricciardo third and Max Verstappen fourth, followed by Ferrari's Sebastian Vettel and Carlos Sainz in the Toro Rosso.

The wild conclusion was fitting for an eventful session that saw the red flag raised four times. The first, after rain had already delayed the start of qualifying by 20 minutes, came when the track was subject to a fresh deluge shortly after the cars finally got out on the circuit. Three more stoppages followed, all in Q1, when Magnus Ericsson, Felipe Massa and Rio Haryanto all failed to keep their cars on the hazardous track.

Such was the disorder on the track and the ensuing uncertainty, the Red Bull duo and others could have faced demotion or even exclusion from the race for not setting times within 107 percent of the fastest lap in Q1. But it was ultimately decided not to enforce the rule strictly, due to “exceptional circumstances.”

After all the disruption, it was Rosberg left smiling widest.

“It was a really challenging qualifying: the conditions changing all the time, very exciting out there,” Rosberg said in the press conference afterward. “In the end it was pretty amazing that it did fully dry out towards the end. Then I just got a really good lap in on that last lap – awesome, I’m very happy with that.”

Having seen his championship lead dwindle to just a solitary point after receiving a five-place penalty two weeks ago at the British Grand Prix and Hamilton winning four of the last five races, the German now has the advantage on a track that offers few opportunities to overtake. And it is an ideal opportunity to correct a poor record in Hungry that has seen never finish higher than fourth.

“I don’t really think of the past in those ways, just looking forward to it now, because of pole position and I’ve been really feeling good out there the whole weekend, in all conditions – wet, dry, even with high fuel on Friday – so it’s been a great weekend so far. Looking forward to the race and a great opportunity tomorrow.”

The session was far less joyous for Hamilton, having been 0.4 seconds faster than Rosberg in the first sector of his final quick lap before being forced to abort. Still, the three-time world champion is far from giving up on his hopes of coming with a victory on Sunday and taking over the lead in the drivers' championship standings for the first time in 2016.

“I don’t know how much Nico was up, but obviously as you said I got the fastest first sector, I was four tenths up, so I felt good on the lap. Bit unfortunate with Fernando, but these things happen. I’m not really too disappointed, it was a tricky session and I did the best I could do and yeah, we still have a long race ahead of us tomorrow, so I’ll give it everything I’ve got from there.”

Despite the spin at the end by Alonso, it was an encouraging day for McLaren, with the Spaniard starting seventh and teammate Jenson Button one place back. Nico Hulkenberg in the Force India and the Williams of Valtteri Bottas will round out the top 10.

Bottas' teammate, Massa, will, though, have to start all the way back in 19th following his Q1 incident. And Ferrari's Kimi Raikkonen was another casualty of the inclement weather, pushed down to 14th on the grid thanks to a rapidly drying track in Q2 that caught out the experienced Finn.

Starting Grid

1. Nico Rosberg (Mercedes)

2. Lewis Hamilton (Mercedes)

3. Daniel Ricciardo (Red Bull)

4. Max Verstappen (Red Bull)

5. Sebastian Vettel (Ferrari)

6. Carlos Sainz (Toro Rosso)

7. Fernando Alonso (McLaren)

8. Jenson Button (McLaren)

9. Nico Hulkenberg (Force India)

10. Valtteri Bottas (Williams)

11. Roman Grosjean (Haas)

12. Daniil Kvyat (Toro Rosso)

13. Sergio Perez (Force India)

14. Kimi Raikkonen (Ferrari)

15. Jolyon Palmer (Renault)

16. Esteban Gutierrez (Haas)

17. Felipe Nasr (Sauber)

18. Marcus Ericsson (Sauber)

19. Felipe Massa (Williams)

20. Kevin Magnussen (Renault)

21. Pascal Wehrlein (Manor)

22. Rio Haryanto (Manor)

Start Time: 8 a.m. EDT

TV Channel: NBCSN

Live Stream: NBC Sports Live Extra