Charles Leclerc led team-mate Carlos Sainz in a surprise Ferrari front-row lockout after a chaotic Mexico City Grand Prix qualifying session.
World champion Max Verstappen appeared primed to take pole for Red Bull after impressing in Q1 and Q2, but the Dutchman could only manage third after the Ferraris came from nowhere to surge to the top of the timesheet.
Leclerc delivered a 1:17.166 on his first run in Q3 to go 0.067 clear on Sainz, and, despite neither Ferrari being able to go quicker on their second run, Verstappen's improvement on his final flying lap was not enough to gatecrash the front row.
- Chaotic Mexico City GP qualifying session - as it happened
- When to watch Mexico City GP live on Sky Sports this weekend
- Stream every F1 race and more on NOW | Get Sky Sports F1
Verstappen faced a near three-hour wait before his third place on the grid was confirmed, with the stewards deciding to take no further action after investigating him for blocking the pit-lane exit during a chaotic finale to Q1.
AlphaTauri's Daniel Ricciardo produced the best moment so far of his return to Formula 1, making a statement by beating Red Bull's Sergio Perez to fourth at the Mexican's home race.
Lewis Hamilton also had to wait for the outcome of a post-session investigation, for not slowing down under yellow flags at the end of Q1, before his sixth place was confirmed.
Oscar Piastri took seventh for McLaren, but the team will be left hugely disappointed after poor execution led to a shock Q1 exit for Lando Norris.
George Russell, who was also cleared of blocking the end of the pit lane in Q1 after an investigation, took eighth ahead of Alfa Romeo duo Valtteri Bottas and Zhou Guanyu.
After sealing a fourth pole position of the season - and his second in a row after also topping qualifying at last weekend's United States Grand Prix - Leclerc will be looking to end a streak of 10 starts from the front of the grid that he has failed to turn into victory.
Mexico City GP Qualifying result
1) Charles Leclerc, Ferrari
2) Carlos Sainz, Ferrari
3) Max Verstappen, Red Bull
4) Daniel Ricciardo, AlphaTauri
5) Sergio Perez, Red Bull
6) Lewis Hamilton, Mercedes
7) Oscar Piastri, McLaren
8) George Russell, Mercedes
9) Valtteri Bottas, Alfa Romeo
10) Zhou Guanyu, Alfa Romeo
Ferraris come from nowhere to stun Verstappen
Ferrari's pace was something of a mystery going into qualifying after both drivers' final runs in Practice Three had been ruined by traffic, but even going into the final 12 minutes of the session, there was little clue of what was to come.
Sainz had only just scraped through to Q3 by the narrowest of margins in P9, while Leclerc finished Q2 in sixth, three tenths off the time Hamilton had topped Q2 with.
Meanwhile, Verstappen, who had headed all three practice sessions, appeared to have ominous speed and had the luxury of sitting in his garage at the end of Q2 having already set a strong enough time to advance with his first effort.
Verstappen was first to go in Q3 and appeared to have set a decent time as he out-paced Ricciardo and Perez, but then came the Ferraris, with Sainz first bettering the Red Bull before Leclerc went even faster.
It was the Ferraris who went first on the final runs, and they looked to have left the door open for Verstappen when failing to improve, but his marginal gain was not enough.
The last car on a flying lap, Hamilton, was also able to improve, but only enough to take sixth, which may be a disappointing result for Mercedes on a weekend where they had hoped to challenge Red Bull.
"I did not expect to be on pole today," Leclerc said. "We thought we were lacking quite a bit after FP3.
"But for some reason, once we put everything together it went well and on the new tyres we gained a lot."
The surprising results may be partially explained by the unique conditions of the Autodromo Hermanos Rodriguez, which sits at a high altitude that creates rarely-seen impacts on various elements of the car, perhaps most crucially the tyres.
Unfortunately for Ferrari, the same thing that helped them in qualifying may prove to be their downfall on Sunday, with the Italian team expected to suffer more significant tyre wear than their rivals over race distance.
That means Verstappen will still start as the clear favourite to claim a record 16th victory of the season, as he continues to rewrite the sport's history books after sealing a third successive drivers' title.
Why were Verstappen and Mercedes duo under investigation?
Before Ferrari stole the show in Q3, there had been a wild start to the session with most of the issues stemming from overcrowding at the end of the pit lane.
At the end of Q1, several cars attempted to come out of the pits in the closing stages, only to be blocked by Verstappen, Russell, and Fernando Alonso who held station at the exit as they sought the optimum moment to leave the pits, and subsequently avoid breaking another rule by going too slowly on their out-laps.
In clearing all three of the offence, the stewards admitted that rules prohibiting both pit lane exit impeding, and going over a maximum time on non-flying laps, are "contrary requirements", and that breaching the former is less dangerous than having cars at vastly different speeds on track.
The investigations concluded that a better solution for the pit lane exit is "desirable", but currently "unknown".
By the time the group had made it around to start their flying laps, Alonso's spin at Turn 3 brought out yellow flags in the first sector which compromised a significant number of cars behind him.
The biggest loser was Norris, who had been left exposed after inexplicably choosing not to set a time on medium tyres on his first Q1 run, and then botching his first attempt at a flying lap on soft tyres.
He may not have been able to improve enough to advance as he attempted another lap on those same soft tyres, but lost the opportunity when Alonso span.
Hamilton was also among the cars behind Alonso, and was called to the stewards regarding an alleged failure to slow down under the yellow flags, before later being cleared.
The only driver to be punished for an infringement was Williams' Logan Sargeant, after he overtook the AlphaTauri of Yuki Tsunoda under the yellow flags.
Sargeant received a 10-place grid drop, which will have no impact after he qualified last, but more significantly, two penalty points on his FIA super licence.
There were similarly wild scenes in the pit lane at the end of Q2 as Tsunoda made contact with a Williams rear jack as he made his way out of the garage, for which the team were fined for leaving unattended.
Alex Albon, who had shown impressive pace to finish second in final practice, appeared to have snuck his Williams into Q3 before losing the time for breaching track limits at Turn 2.
Zhou and Norris were cleared for exceeding the maximum lap-time allowed during qualifying, as the stewards once more opted not to impose a penalty for an offence that has occurred repeatedly since the rule was brought in for September's Italian Grand Prix.
When to watch the Mexico City GP live only on Sky Sports F1
Sunday
6.30pm: Grand Prix Sunday Mexico City GP build-up (also on Sky Sports Main Event)
8pm: The MEXICO CITY GRAND PRIX (also on Sky Sports Main Event)
10pm: Chequered Flag: Mexico City GP
F1 is in Mexico for the middle leg of the Americas triple header. Watch the whole Mexico City Grand Prix weekend live on Sky Sports F1, with Sunday's race at 8pm. Stream F1 on Sky Sports with NOW