The world champion had been trailing behind Lewis Hamilton as he began his second and final effort at the end of Q3, but saved his best until last as he lapped the Hungaroring in one minute 19.815 seconds, just 0.163 seconds ahead of the McLaren driver.
Jenson Button made it two McLarens inside the front three while a superb late effort by Felipe Massa gave him fourth spot, demoting his Ferrari team-mate Fernando Alonso to fifth and the Red Bull of last year's race winner Mark Webber to sixth.
Adrian Sutil was a superb eighth for Force India, splitting Mercedes drivers Nico Rosberg and Michael Schumacher as the trio - unlike the top six - only undertook a single flying lap in Q3. Sergio Perez, who will start 10th for Sauber, did not bother going out at all.
There was a gap of almost two seconds from first to 10th with a couple of minutes of Q2 remaining, the result of which was that the top seven at that moment - led by Button - did not undertake second runs.
All of those drivers had done enough to make it into Q3, but behind them the order was constantly changing. Late flyers for Sutil and Schumacher brought the Force India and Mercedes drivers into the top 10 after the chequered flag had come out.
The big loser was Sutil's team-mate Paul di Resta, who was bumped back to 11th. The Renaults of Vitaly Petrov and Nick Heidfeld were 12th and 14th, split by Kamui Kobayashi's Sauber, while Rubens Barrichello and Jaime Alguersuari were next up for Williams and Toro Rosso.
Barrichello's team-mate Pastor Maldonado did not venture out in Q2, after the Venezuelan pulled himself into the session at the very end of Q1 with a flying lap. The Williams driver knocked Sebastien Buemi's Toro Rosso out of the reckoning.
Behind him were his team-mate Jarno Trulli, Virgin's Timo Glock and Hispania drivers Vitantonio Liuzzi and Daniel Ricciardo, all of whom will move ahead of Buemi once his five-place grid penalty for colliding with Heidfeld in German last weekend is applied.
- Related links