All the signs here at the Autodromo Hermanos Rodriguez pointed towards a Verstappen triumph, but the Silver Arrows stole the show to provide Hamilton with a timely boost in his quest for a record-breaking eighth crown.
Verstappen, who leads Hamilton by 12 points with just five races left, had to settle for only third, one spot behind his championship rival.
The venue here in Mexico City sits 2,285 metres above sea level and Bottas delivered a breath-taking lap with his first run in Q3, finishing 0.145 seconds clear of Hamilton, with Verstappen three tenths adrift.
None of the top three improved on their second attempts with home favourite Sergio Perez appearing to scupper Red Bull team-mate Verstappen’s lap when he fell off the road ahead of him. Perez qualified fourth.
“Valtteri did a great job and I am so proud of him,” said Hamilton as he was jeered by the swathes of Red Bull fans supporting Perez.
“We did not think we had the pace here this weekend so to lock out the front row was pretty special.
“I am just as shocked as anyone. I would love to be in Valtteri’s position but he did a fantastic first run in Q3. I gave it my all but he did a better job.”
Verstappen added: “Qualifying did not go our way but there is still a lot to play for.”
Pierre Gasly finished fifth for AlphaTauri, while Lando Norris took 10th but he will be thrown to the back of the grid after taking on his fourth engine of the season here – one more than is permitted.
Q1 was delayed by 26 minutes after Lance Stroll crashed out.
The Canadian driver lost control of his Aston Martin on the exit of the final right-hand corner before slamming into the nearside barrier.
Stroll was unharmed in the accident, but he sustained significant damage to his car.
Stroll was escorted back to the pits in the medical car, while his wrecked machine was put on a flat-bed truck.
The 23-year-old underwent precautionary checks following the shunt which registered at 12G.
FIA race director Michael Masi then left his office to attend the accident scene, overseeing a series of hasty repairs to the damaged tyre wall.
When Q1 resumed, Fernando Alonso was the major casualty, knocked out in 16th.
But the Spaniard will be bumped up the grid with his Alpine team-mate Esteban Ocon and AlphaTauri’s Yuki Tsunoda thrown to the back following engine penalties.
George Russell finished 13th, but he will also serve a grid drop – five places for taking on a new gearbox.