Sebastian Vettel claimed pole position for the Bahrain Grand Prix after pipping Ferrari Formula 1 team-mate Kimi Raikkonen by 0.143s.
Raikkonen had the advantage after the first runs in Q3 by 0.095s from Vettel, but failed to improve on his second run.
Vettel, who had a precautionary change of the control electronics of his power unit ahead of qualifying, then banged in a lap of 1m27.958s using the supersofts that were the tyre of choice to secure his 51st F1 pole position.
Valtteri Bottas was third, just 23 thousandths of a second behind Raikkonen after making a two-tenths improvement on his final lap.
That put him just ahead of Mercedes team-mate Lewis Hamilton, who has a five-place grid penalty so is set to line up ninth.
Hamilton was the only driver to set his Q2 time using soft-compound Pirellis, so he will start the race on that tyre.
Daniel Ricciardo was fifth fastest, almost two-tenths slower than Hamilton and nearly a second clear of the chasing pack.
Pierre Gasly put in a superb performance to secure his best qualifying result in F1 with sixth place, and is set to move up to fifth on the grid thanks to Hamilton's penalty.
Kevin Magnussen was just 29 thousandths of a second slower in seventh, with the Renaults of Nico Hulkenberg and Carlos Sainz Jr sandwiching the Force India of Esteban Ocon in ninth.
Brendon Hartley missed out on making it two Toro Rossos in Q3 by less than a tenth of a second, after a small mistake in the final corner on his only effort in Q2 using fresh supersofts left him 11th.
That put him just ahead of Sergio Perez in the second Force India, with the McLarens of Fernando Alonso and Stoffel Vandoorne never looking to have top 10 pace and ending up 13th and 14th after struggling for grip.
Max Verstappen lost the rear of his Red Bull and spun exiting the slow Turn 2 left-hander while on the fourth lap of his Q1 run.
He hit the barrier with his front wing and front left wheel, which led to the session being red flagged with five-and-half minutes remaining.
Verstappen ended Q1 fourth fastest, so technically made it to Q2, but was unable to run again after the crash and was classified 15th.
Romain Grosjean was fastest of those eliminated in Q1 despite setting an identical lap time to Alonso in the first segment of qualifying.
The Haas driver's late 1m30.530s lap during the five-and-a-half minutes of running after the red flag caused by Verstappen left him down in 16th and ranked behind Alonso, thanks to the McLaren driver setting his time first.
Grosjean subsequently complained over the radio about his outlap being "a mess".
Sauber's Marcus Ericsson failed to improve on his third and final Q1 run and ended up 17th ahead of Williams driver Sergey Sirotkin, who had to rely on his first-run time.
Charles Leclerc declared himself to be "so stupid" over the radio after spinning at the final corner on his last lap and ending up 19th.
His best lap, set on the second of three sets of tyres as the Sauber drivers and Hartley managed to squeeze in two runs before the red flag, was just 0.006s slower than Sirotkin.
Lance Stroll was slowest, the Williams driver just under a tenth slower than Leclerc.
Bahrain GP grid
|4||Daniel Ricciardo||Red Bull/Renault||1m28.398s||0.440s|
|5||Pierre Gasly||Toro Rosso/Honda||1m29.329s||1.371s|
|8||Esteban Ocon||Force India/Mercedes||1m29.874s||1.916s|
|10||Carlos Sainz Jr.||Renault||1m29.986s||2.028s|
|11||Brendon Hartley||Toro Rosso/Honda||1m30.105s||2.147s|
|12||Sergio Perez||Force India/Mercedes||1m30.156s||2.198s|
|15||Max Verstappen||Red Bull/Renault||-||-|