The Brit broke the track record with his lap of 1 minute 32.237 seconds, and it was good enough to hold Vettel at bay by just 0.061 seconds after a closely fought top-10 shootout.
Vettel qualified second, but a three-place grid penalty earnt for disobeying red flag rules during practice will demote him to fifth on the grid.
Hamilton led the way after the first runs, but even then it was by less than a tenth, with Vettel threatening from just 0.088 seconds back.
Kimi Raikkonen then swept in to take provisional pole at the beginning of the second runs, but the track was improving rapidly after heavy rain had soaked the circuit throughout Friday (Oct 19), giving advantage to those crossing the line last.
Hamilton was next to set his time, taking the top position back from the Finn, but Vettel had set a record-breaking first sector behind him and was threatening to usurp him.
But the German suffered a snap of oversteer at turn eight, losing him time in sector two. He was unable to recover, and he crossed the line fractionally behind his foe.
“That was very important, that was close,” Hamilton said jubilantly after the session. “I knew it was quite edgy between us [and Ferrari] and it was going to require solid laps.
“The first one was decent but not good enough, the second one was just that little bit better.”
Vettel was despondent out of the car, having earlier exchanged expletives with his engineer over pit-to-car radio on his cool-down lap.
“A bit of a shame when you miss out by just that little time,” he said. “I was quite happy with the laps that I had. It’s quite tricky to get everything together.”
Hamilton must outscore Vettel by eight points to claim the championship this weekend, meaning the German can recover to no higher than third if the Brit converts his pole into victory.
The responsibility to disrupt Hamilton’s race falls to Raikkonen, who qualified third and just 0.07 off the pace.
The Finn will start the race from second on the grid and, perhaps crucially, with a grippier set of tyres than Hamilton with the aim of jumping the leading Mercedes car and giving Vettel a chance to catch up.
“Nobody really knows how the tyres are going to survive because of yesterday’s rain, so we’ll see,” he said. “It’s been a pretty positive day.
“I feel good with the car. We’ll try tomorrow. It’s going to be a long race.”
Valtteri Bottas and Daniel Ricciardo qualified fourth and fifth, but both will move up a place ahead of the penalised Vettel on Sunday’s grid.
Esteban Ocon qualified sixth for Force India, just 0.07 ahead of Renault’s Nico Hulkenberg.
Romain Grosjean put Haas into eighth on the grid for its home race, keep at arm’s length Sauber’s Charles Leclerc and Force India’s Sergio Perez.
Lewis Hamilton, Valtteri Bottas, Sebastian Vettel and Daniel Ricciardo took to the track on the supersoft tyre, which would allow them to start on that more durable compound in the race if they qualified for the top-10 shootout.
Kimi Raikkonen stuck with the softest ultrasoft tyre and topped the session, with Vettel, Hamilton and Bottas followed him on the time sheet, but Ricciardo was 1.3 seconds off the pace after his first lap.
His Red Bull Racing team opted not to send him out for a second run, risking an early elimination on the rapidly improving circuit to save him a set of tyres, but the gamble paid off for the Australian, who progressed to the top-10 shootout.
Carlos Sainz was the quickest driver eliminated from the session, Spaniard knocked out in 11th just 0.002 seconds behind Renault teammate Nico Hulkenberg. Dane Kevin Magnussen followed for the American Haas team in 12h.
Toro Rosso’s Pierre Gasly and Brendon Hartley opted not to set a time as both will be demoted to the back of the grid for regardless of result thanks to a litany of power unit penalties.
Max Verstappen was knocked out in P15, but he didn’t take part in the session after damaging his car in Q1.
Q1 was only the second dry session of the weekend, making for a busy circuit.
Max Verstappen caused the first drama, the Red Bull Racing driver crawling back to the pits with five minutes to go complaining of a lack of drive. His rear-right suspension appeared damaged, and replays showed him drifting wide over some high kerbs at turn 15.
The Dutchman had already set a representative time to progress into Q2, but the car was retired from the rest of the afternoon.
Focus resumed on the fight at the back, where McLaren’s Fernando Alonso was the man most likely to make the lad into the second session at the expense of Toro Rosso’s Brendon Hartley.
It became a straight fight between the Spaniard and the Kiwi, with the latter setting a poor first sector that put him on the bubble, but he managed to recover over the rest of the lap to fend off his rival by 0.088 seconds.
Sergey Sirotkin and Lance Stroll qualified 17th and 18th respectively ahead of Sauber’s Marcus Ericsson.
Stoffel Vandoorne, who announced his defection to Formula E during the week, qualified last and almost half a second behind teammate Alonso.
All five drivers will be moved up two places, however, when both Toro Rosso drivers are demoted to the back of the grid for exceeding their allocation of Honda power unit parts.