Nico Rosberg had a clear run to pole position for the Hungarian Grand Prix after team-mate Lewis Hamilton's Mercedes caught fire early in qualifying.
Hamilton was the favourite for pole after topping all three free practice sessions, but he was eliminated just five minutes into Q1 when he stopped in the pit entry with the rear of his Mercedes ablaze thanks to a fuel leak.
But although this meant Rosberg's main rival was not in contention, rain that struck at the start of Q3 made the world championship leader's task difficult.
Rosberg was the first onto the track on slick tyres with conditions worsening, but with the first corner particularly wet he slid off into the runoff area on his first flier, ruining his lap.
But Kevin Magnussen, who was second on the road, also outbraked himself, hitting the tyre barrier on the outside of the corner and bringing out the red flag before anyone could set a time.
When qualifying resumed after an eight-minute delay, the rain had eased and while the track was slippery, everyone opted to continue on slicks.
With the track drying up, everyone went back out on slicks, with Rosberg going fastest on his second flying lap after a brief spell at the top of the times for Williams driver Valtteri Bottas.
But unlike Rosberg, who stayed out and used only one set of softs in Q3, Vettel pitted for new rubber and took top spot from the Mercedes driver on his final lap.
Moments later Rosberg improved, taking pole position by almost half-a-second.
Vettel held onto second ahead of Bottas, the latter also opting to pit for new tyres, with Daniel Ricciardo fourth fastest.
Fernando Alonso and Felipe Massa were fifth and sixth, both also having two runs in the restarted Q3 segment, with Jenson Button eighth ahead of Jean-Eric Vergne.
Force India driver Nico Hulkenberg was the slowest of those to set a time in Q3 in ninth, with Magnussen classified 10th having not set a time before his crash.
Daniil Kvyat was in contention for a top 10 slot, but he locked the rears at Turn 12 on his final lap in Q2 and spun, ending up 11th.
Sauber driver Adrian Sutil was 12th ahead of Sergio Perez, who suffered a hydraulic leak during Q2 and could only attempt one run.
Esteban Gutierrez took 14th ahead of Romain Grosjean, with Jules Bianchi ending up 16th after an excellent performance to make the second stage of qualifying.
Kimi Raikkonen was a shock casuality during Q1, ending the session 17th fastest.
With Hamilton and Pastor Maldonado, whose Lotus had stopped early in Q1, not running, most teams opted not to send their cars out for a second run on the basis that they only needed to finish ahead of the Caterhams and the Marussias to make the next phase.
But Raikkonen was the slowest of those who did not attempt a run on soft rubber and when Bianchi put in his final lap, the Finn was relegated to the dropzone while sat in the garage.
Caterham driver Kamui Kobayashi was 18th ahead of Max Chilton, who suffered a fuel pressure problem on his final run, with Marcus Ericsson slowest of those who set a lap.
Hamilton was classified 21st ahead of Maldonado thanks to starting a flying lap.
Pos Driver Team/Car Time Gap
1. Nico Rosberg Mercedes 1m22.715s
2. Sebastian Vettel Red Bull-Renault 1m23.201s +0.486s
3. Valtteri Bottas Williams-Mercedes 1m23.354s +0.639s
4. Daniel Ricciardo Red Bull-Renault 1m23.391s +0.676s
5. Fernando Alonso Ferrari 1m23.909s +1.194s
6. Felipe Massa Williams-Mercedes 1m24.223s +1.508s
7. Jenson Button McLaren-Mercedes 1m24.294s +1.579s
8. Jean-Eric Vergne Toro Rosso-Renault 1m24.720s +2.005s
9. Nico Hulkenberg Force India-Mercedes 1m24.775s +2.060s
10. Kevin Magnussen McLaren-Mercedes
Q3 cut-off time: 1m24.647s
11. Daniil Kvyat Toro Rosso-Renault 1m24.706s +1.396s**
12. Adrian Sutil Sauber-Ferrari 1m25.136s +1.826s
13. Sergio Perez Force India-Mercedes 1m25.211s +1.901s
14. Esteban Gutierrez Sauber-Ferrari 1m25.260s +1.950s
15. Romain Grosjean Lotus-Renault 1m25.337s +2.027s
16. Jules Bianchi Marussia-Ferrari 1m27.419s +4.109s
Q2 cut-off time: 1m26.728s
17. Kimi Raikkonen Ferrari 1m26.792s +1.851s***
18. Kamui Kobayashi Caterham-Renault 1m27.139s +2.198s
19. Max Chilton Marussia-Ferrari 1m27.819s +2.878s
20. Marcus Ericsson Caterham-Renault 1m28.643s +3.702s
21. Lewis Hamilton Mercedes
22. Pastor Maldonado Lotus-Renault
107 per cent time: 1m30.886s
** Gap to fastest in Q2
*** Gap to fastest in Q1