Nico Rosberg snatched pole position from his championship rival Lewis Hamilton for Sunday's Hungarian Grand Prix with his final throw of the dice in a dramatic qualifying session.
Hamilton, who is just one point adrift of Rosberg in the title race, appeared on course to secure pole, but, courtesy of being in the wrong place at the wrong time, had to abort his final timed run after Fernando Alonso spun ahead of him in his McLaren.
It allowed Rosberg, who was further behind his Mercedes team-mate on the track, to improve on his time with his very last lap to secure pole. Daniel Ricciardo and Max Verstappen will line up on the second row for Red Bull.
"It was a really challenging qualifying with conditions changing the whole time" - Nico Rosberg
Hamilton set the fastest first sector - he was four tenths of a second up on his previous time - but was forced to back off following Alonso's spin.
"I don't know how much Nico was up, but I felt good on the lap and it was a bit unfortunate with Fernando, but these things happen," a diplomatic Hamilton said. "I am not too disappointed. There is a long race ahead of us tomorrow."
Hamilton knows that a victory here, which would be a record-breaking fifth at the Hungaroring, will see him lead the championship for the first time this season. But the defending champion now faces an uphill challenge to beat his team-mate following his piece of misfortune on Saturday.
A deluge of rain before the session contributed to chaotic scenes in the opening phase of qualifying. Four red flags were issued - one following a further outbreak of rain - and three after Marcus Ericsson, Felipe Massa and Rio Haryanto all crashed out. Indeed Q1, which is scheduled to last only 18 minutes, took nearly one hour to complete.
As the sun emerged, Q2 was played out on a drying track, and Hamilton must consider himself somewhat fortunate to have progressed to Q3 after ending up in 10th following a mistake at turn one.
McLaren have endured a troubled 18 months, but they have impressed here this weekend and Alonso and Jenson Button will line up in seventh and eighth on the grid.
Meanwhile, Jolyon Palmer will start 17th after he failed to progress beyond Q1. "Oh, f****** hell, that's really poor," he fumed over the team radio.
Elsewhere, Ferrari's Sebastian Vettel qualified fifth with Carlos Sainz an impressive sixth for Toro Rosso. The Force India of Nico Hulkenberg and Williams' Valtteri Bottas completed the top 10.
Rosberg, who has never finished on the podium in his 10 previous visits to the Hungaroring, will be desperate to get his championship bid back on track after seeing Hamilton win four of the last five grands prix, and take 42 points out of his lead.
"It was a really challenging qualifying with conditions changing the whole time," Rosberg said. "It was very exciting out there, and it was amazing that it did fully dry out in the end. I got a really good lap in with that last lap so I am very happy."