Baku - Lewis Hamilton snatched pole position for Sunday's Azerbaijan Grand Prix after eclipsing Mercedes team-mate Valtteri Bottas on his final qualifying lap on Saturday.
The three-time world champion starts ahead of Bottas with Ferrari duo Kimi Raikkonen and Sebastian Vettel, the championship leader, occupying the second row of the grid.
Hamilton claimed the 66th pole of his career, pulling clear of Brazilian great Ayrton Senna's mark and leaving the Briton just two shy of Michael Schumacher's record of 68.
The 32-year-old bounced back from a frustrating practice outing on Friday to clinch his fifth pole in eight races this season as Mercedes locked out the front row.
Hamilton's quickest lap of 1:40.593 came in the final seconds of the session following a red-flagged stoppage which turned the finale into a 3:30 showdown.
"I am so pumped - that’s how qualifying should be," said an ecstatic Hamilton, who was more than a second off the pace on Friday. "It is going to be a long hard race, but it’s the best place to start."
Bottas, who had been fastest in Q3 until Hamilton’s stunning final lap, admitted he was disappointed.
"The lap, in the end, wasn’t quite perfect, I was struggling the front left temperature and Lewis then did his lap! It’s disappointing, but second place is not bad."
Hamilton is 12 points behind Vettel in the championship after seven races.
Max Verstappen was fifth for Red Bull ahead of the two Force Indias of Sergio Perez and Esteban Ocon, Canadian teenager Lance Stroll who was eighth ahead of his Williams team-mate Felipe Massa and Australian Daniel Ricciardo, who crashed his Red Bull to engage the red flag and create the final drama.
The starting grid for Sunday's Azerbaijan Grand Prix after qualifying on Saturday in Baku:
1st row
Lewis Hamilton (GBR/Mercedes)
Valtteri Bottas (FIN/Mercedes)
2nd row
Kimi Raikkonen (FIN/Ferrari)
Sebastian Vettel (GER/Ferrari)
3rd row
Max Verstappen (NED/Red Bull)
Sergio Perez (MEX/Force India)
4th row
Esteban Ocon (FRA/Force India)
Lance Stroll (CAN/Williams)
5th row
Felipe Massa (BRA/Williams)
Daniel Ricciardo (AUS/Red Bull)
6th row
Daniil Kvyat (RUS/Toro Rosso)
Kevin Magnussen (DEN/Haas)
7th row
Nico Hülkenberg (GER/Renault)
Pascal Wehrlein (GER/Sauber)
8th row
Carlos Sainz Jr (ESP/Toro Rosso)
Romain Grosjean (FRA/Haas-Ferrari)
9th row
Marcus Ericsson (SWE/Sauber)
Fernando Alonso (ESP/McLaren)
10th row
Stoffel Vandoorne (BEL/McLaren)
Jolyon Palmer (GBR/Renault)