Kimi Raikkonen was third-fastest in the second Ferrari ahead of Valtteri Bottas in the second Mercedes with Daniel Ricciardo fifth for Red Bull.
Esteban Ocon was an impressive sixth for Force India ahead of Nico Hulkenberg of Renault, Romain Grosjean of Haas, Charles Leclerc of Sauber and Sergio Perez in the second Force India.
“That was close and I didn’t know how close it was going to be when we got down to it,” said Hamilton.
“I knew it was edgy between us on my last run, but my second lap was just that little bit getter and that enabled me to pull it out.
“I was adamant that I was going to do a better second lap so I am very happy with that.”
It was Hamilton’s third successive pole at the Circuit of the Americas and the 81st pole of his career.
“That was pretty close and it is always a bit of a shame when you miss out by such a little time,” said Vettel. “But I was pretty happy with the laps I had.
“It was tricky to get it all together, but given the last few weeks that we have had, I am pretty happy that we are back in range.”
Raikkonen said: “It’s been a pretty positive day. We are close and I felt good with the car. We will try tomorrow and it will be interesting.”
After a rain-swept Friday, Saturday brought dry, if cool, conditions with a track temperature of 21 degrees and the air at 19, a change that encouraged Ferrari to improve and dominate final practice in the morning.
When qualifying began, the two Ferrari men were swiftly setting the pace with Vettel on top early in Q1. The Mercedes men delayed their first runs, but were soon back in command, Hamilton going quickest in 1:34.176, ahead of Bottas.
The championship leader trimmed his time while, behind him, Max Verstappen’s session was ended when his right rear suspension appeared to fail after he ran across the ‘sausage’ kerbs at Turn 17.
After a final flurry of laps, the five cars eliminated included both McLarens and both Williams along with Sauber’s Marcus Ericsson, a once unthinkable outcome from qualifying.
Fernando Alonso did his utmost, but wound up 16th after being outpaced by Brendon Hartley’s Toro Rosso in the final seconds.
Hamilton climbed out of his Mercedes to greet film star Matthew McConaughey with a hug before returning to the fray, a clear signal of his relaxed mood.
Using ‘super-soft’ tyres, Hamilton was unable to produce his best while the Ferraris led by Raikkonen went quickest again, leaving the Briton third ahead of Bottas.
Only Raikkonen ran on ultra-soft tyres, on which he will start the race while the rest will be on their more-durable ‘supers, enabling greater tactical flexibility for the first part of the race.
Behind them, Carlos Sainz, Kevin Magnussen, Pierre Gasly, Brendon Hartley and Verstappen missed the cut to the top-ten shootout. The Dutchman’s exit meant he was out-qualified by his team-mate Ricciardo for the first time in 12 outings.
On their first Q3 runs, Bottas, Hamilton and Vettel all broke the lap record, the Englishman quickest in 1:32.567, enough to put him 0.088 seconds clear of the resurgent, if penalised, Vettel.
On their final runs, Raikkonen improved again, to go top, but Hamilton exceeded that effort again with another faster lap to take pole for the third consecutive season.
Vettel was second 0.061 seconds adrift of the Briton and, with his penalty, will be fifth on the grid.
“Beautiful work,” Mercedes told Hamilton, who will have Raikkonen alongside him at the start.