Barcelona - Lewis Hamilton secured pole position for Sunday's Spanish Grand Prix for Mercedes in a closely-contested qualifying session at the Circuit de Catalunya on Saturday.
The three-time champion Briton resisted a powerful late challenge in the final seconds of Q3 from championship-leading four-time champion Sebastian Vettel of Ferrari.
"It was very close, but well done to Lewis," said Vettel. "And a big thank-you to my team. I'm afraid it was my lock-up at the end of the lap that made the difference.
"It was a really good lap up to the final chicane."
A beaming Hamilton, who has bounced back to his best form after a puzzling loss of pace in Russia, said his first lap had been "very, very good, but the last lap was only so-so... But I am super proud that we are back up there."
Hamilton clocked a best lap of one minute and 19.149 seconds to stay ahead of Vettel, who clocked 1:19.200, by the narrowest of margins after the German had required a rapid engine change shortly before the session began.
It was the 64th pole of Hamilton's career, lifting him to within one of his childhood hero Brazilian Ayrton Senna, on 65, and four from German Michael Schumacher on 68.
Finns Valtteri Bottas, in the second Mercedes, who also had an engine change on Saturday morning, and Kimi Raikkonen, in the second Ferrari, were third and fourth fastest.
Dutch teenager Max Verstappen, who won last year's race on debut with Red Bull, was fifth ahead of his team-mate Australian Daniel Ricciardo with local hero Fernando Alonso grabbing a very popular seventh against the odds for McLaren-Honda.
On a perfect, if windy, spring day, the session began with a track temperature of 44 degrees Celsius and Vettel hurrying to join the fray after Ferrari had changed his engine following a water leak problem discovered in final practice.
In his third new power unit of the four permitted this year, Vettel used team radio to thank his mechanics for their efforts before being told "stop the car" on his installation lap.
"Are you sure?" he responded, wisely. After making a 'driver default' change in the car, Vettel was soon back up to speed. "Seems better now," he said, as he clocked an early fastest lap in 1:20.939.
Hamilton trimmed four-tenths off that to set the Q1 pace, with Bottas third ahead of Raikkonen, who soon improved to second.
As Q2 began, Mercedes reminded Hamilton "this is our race start set" of tyres, a message not heeded by Bottas who locked up at Turn One and flat-spotted his tyres, requiring a second hot lap.
Hamilton ran wide at Turn Five, but was fastest in Q2 by a narrow margin - less than a tenth - ahead of Vettel and Bottas, but the lap that lifted the crowd came from Alonso, who reached the top ten shootout for the first time this year, 24 hours after yet another engine failure on Friday.
For the Spaniard, who is heading to the Indianapolis 500 instead of Monaco later this month, it was a personal triumph four years after his last victory, with Ferrari in Spain, in 2013.
1. Lewis Hamilton (Britain) Mercedes 1:19.149
2. Sebastian Vettel (Germany) Ferrari 1:19.200
3. Valtteri Bottas (Finland) Mercedes 1:19.373
4. Kimi Raikkonen (Finland) Ferrari 1:19.439
5. Max Verstappen (Netherlands) Red Bull - TAG Heuer 1:19.706
6. Daniel Ricciardo (Australia) Red Bull - TAG Heuer 1:20.175
7. Fernando Alonso (Spain) McLaren 1:21.048
8. Sergio Perez (Mexico) Force India - Mercedes 1:21.070
9. Felipe Massa (Brazil) Williams-Mercedes 1:21.232
10. Esteban Ocon (France) Force India - Mercedes 1:21.272
- - - - - - - - - -
11. Kevin Magnussen (Denmark) Haas - Ferrari 1:21.329
12. Carlos Sainz Jr (Spain) Toro Rosso - Renault 1:21.371
13. Nico Huelkenberg (Germany) Renault 1:21.397
14. Romain Grosjean (France) Haas - Ferrari 1:21.517
15. Pascal Wehrlein (Germany) Sauber - Ferrari 1:21.803
- - - - - - - - - -
16. Marcus Ericsson (Sweden) Sauber - Ferrari 1:22.332
17. Jolyon Palmer (Britain) Renault 1:22.401
18. Lance Stroll (Canada) Williams-Mercedes 1:22.411
19. Stoffel Vandoorne (Belgium) McLaren 1:22.532
20. Daniil Kvyat (Russia) Toro Rosso - Renault 1:22.746
- - - - - - - - - -
1-10: third and final qualifying session
11-15: second qualifying session
16-20: first qualifying session