Vettel was fastest in final practice at the Hungaroring, led the way in Q1 as well, and was the first F1 driver to lap under under 1m17s around the Hungaroring in Q2, before Hamilton made a second run.
Vettel then set a 1m16.276s best on his first run in Q3 which proved enough to get the job done despite lapping slightly slower on his second attempt.
Ferrari teammate Kimi Raikkonen snatched a brake at Turn 1 on his first run in Q3 so was down in fifth, but he improved dramatically on his second run to leap to second, within two tenths of Vettel's mark.
Hamilton went off at Turn 4 on his first run in Q2 and did so again in Q3. He struggled for grip throughout qualifying, complained of vibrations through the tyres, and ultimately wound up only fourth fastest, more than four tenths off the pace.
Mercedes struggled in the first sector of the lap compared to Ferrari and Hamilton's teammate Valtteri Bottas was only third quickest, 0.163s clear of Hamilton.
Max Verstappen was second fastest in Q1 and third in Q2, but Red Bull faded from the pole position fight in Q3. Verstappen was fifth fastest, a tenth behind Hamilton, while teammate Daniel Ricciardo was sixth, only 0.021s adrift despite missing most of FP3 with a hydraulic problem.
Nico Hulkenberg was quicker than Ricciardo in Q2 and ended up best of the rest in the best of the works Renaults, just under a tenth clear of Fernando Alonso's McLaren-Honda.
Stoffel Vandoorne made Q3 for the second race in a row and qualified ninth, three tenths behind Alonso.
Carlos Sainz's Toro Rosso rounded out the top 10, after making only a nominal run in Q3.
The second Renault of Jolyon Palmer was 11th fastest, missing the Q3 cut by a tenth of a second.
Esteban Ocon was best of the Force Indias in 12th, ahead of Daniil Kvyat's Toro Rosso, Force India teammate Sergio Perez and Romain Grosjean's Haas.
Grosjean's Haas teammate Kevin Magnussen matched Perez to the thousandth of a second in Q1, but missed the Q2 cut by account of setting his best time later than the Force India driver.
Lance Stroll's Williams was only 0.007s further back in 17th, while emergency stand-in teammate Paul di Resta outstandingly split the Saubers of Pascal Wehrlein and Marcus Ericsson to qualify 19th for his first grand prix since 2013.
Di Resta achieved this despite not having driven a 2017 F1 car before, and only turning his first laps of the weekend in qualifying after Felipe Massa fell ill in final practice.
The Sauber drivers ended up more than seven tenths adrift of Stroll's Williams, despite planning to run their year-old Ferrari engines at full power for the first time this season, after having cooling updates fitted to the cars.