Red Bull had looked favourites to take pole around the Autodromo Hermanos Rodriguez after dominating throughout practice, but Bottas and Hamilton turned things around in Q3 as Mercedes responded with a huge statement.
Bottas beat Hamilton to secure just his third pole of the season with a stunning first lap that was 0.145s quicker than his teammate, while Verstappen was a frustrated third for Red Bull.
A messy opening run left Verstappen 0.350s behind Bottas before his final lap was ruined after Yuki Tsunoda and Red Bull teammate Sergio Perez both ran wide in the middle sector, leaving him only third.
Mercedes’ remarkable turnaround coincided with Red Bull’s qualifying going the opposite way. Red Bull appeared to encounter a rear wing issue that affected its cars, with mechanics seen frantically working on the rear of Verstappen and Perez’s cars in the build up to Q1.
Home hero Perez ended up fourth ahead of AlphaTauri’s Pierre Gasly and Carlos Sainz’s Ferrari, who pipped McLaren’s Daniel Ricciardo by just 0.002s.
Charles Leclerc, Tsunoda and Lando Norris completed the rest of the top 10 for Ferrari, AlphaTauri and McLaren.
Sebastian Vettel failed to progress into Q3 as he fell three-tenths shy of the top 10 in the highest-placed Aston Martin.
Two tenths behind Vettel was Kimi Raikkonen in 12th, though the Alfa Romeo driver is under investigation for crossing the white line at the end of the pit lane and continuing under red flag conditions.
George Russell recorded another Q2 appearance in his Williams on his way to 13th, though he is carrying a five-place grid penalty into the race following a gearbox change that will see him drop down the starting order.
A spin at Turn 12 in the closing stages of the second session left Alfa Romeo’s Antonio Giovinazzi in 14th, ahead of Esteban Ocon as Alpine struggled for pace.
Fernando Alonso was the shock elimination of Q1 in a miserable qualifying for Alpine after the two-time world champion was denied a spot in Q2 by his teammate who is carrying an engine penalty.
The Spaniard ended qualifying only 16th, ahead of the Haas duo of Mick Schumacher and Nikita Mazepin, who were split by nearly half a second.
Q1 was interrupted by an early red flag following a big crash for Lance Stroll at the Peraltada when the Canadian got wide onto the dirty part of the track exiting the corner and lost control, spinning violently into the barriers.
The incident caused a lengthy delay to the session while barrier repair work was carried out.
Due to crossing the line as he crashed, Stroll, who was unhurt in the shunt, still managed to set a lap time, albeit by far the slowest of the 20 drivers.
It ultimately made little difference given Stroll was already set to start from the back of the grid after taking an engine penalty, along with Tsunoda, Norris and Ocon.