Max Verstappen upset Ferrari to take pole position at the Mexican Grand Prix, only for a post-session penalty to see P1 change to Charles Leclerc's hands.
Verstappen has been victorious at the Autodromo Hermanos Rodriguez in each of the past two years, and had entered the weekend pessimistic about the chance of a hat-trick.
Verstappen's pole time was 0.001 seconds quicker than Daniel Ricciardo's record time of last year, but the satisfaction soon soured, as Verstappen passed the crashed car of Valtteri Bottas, and yellow flags, at the final corner of his lap.
Stewards imposed a three-place grid penalty on Verstappen, dropping him to fourth.
Leclerc inherits pole - Ferrari's sixth in succession - with teammate Sebastian Vettel alongside him on the front row and Lewis Hamilton in third.
Hamilton's new grid slot is notable. If Bottas car is damaged to the extent that grid penalties follow, third could be enough for Hamilton to secure a sixth world championship, if his team-mate does not score points.
Bottas became stuck in the wall and skated firmly into the edge of the tyre barrier, which protruded slightly to give the Finn a serious jolt, leaving him audibly struggling for breath in the cockpit.
Alexander Albon qualified P5, while Carlos Sainz and Lando Norris secured an all-McLaren fourth row and the Toro Rossos of Daniil Kvyat and Pierre Gasly filled the fifth.
Last year's polesitter, Daniel Ricciardo could not make the top-10 shootout, with Renault struggling after a pre-session rebuild on both cars as Nico Hulkenberg also dropped out. Sergio Perez was 11th-fastest in his home race, with the Alfa Romeo pair of Kimi Raikkonen and Antonio Giovinazzi also dropping out.
There were few surprises as Williams saw both cars go out, as did Haas – who have never had a driver escape Q1 in Mexico – and Lance Stroll for Racing Point.