Lewis Hamilton edged out Mercedes Formula 1 team-mate Nico Rosberg to take pole position for the Bahrain Grand Prix, as Ferrari's challenge fizzled out late in the session.
Ferrari looked genuinely competitive in qualifying at Sakhir, and unlike at the previous race in Melbourne retained enough sets of super-soft tyres to attack Mercedes to the end of qualifying.
Hamilton was only fourth fastest after running wide at the final corner on his first run in Q3, but he produced the fastest lap of the weekend so far - a 1m 29.493s - when it counted to take the 51st pole of his F1 career.
Rosberg led the way following the first runs in Q3, just under two tenths clear of Sebastian Vettel's Ferrari. Rosberg improved by more than three tenths of a second on his second run, but Hamilton remained 0.077s clear.
Vettel took third, improving only fractionally on his first Q3 effort, while team-mate Kimi Raikkonen dropped time in the first sector on his final lap so wound up fourth.
The rest of the Q3 runners only had sufficient time to complete single runs, thanks to the controversial elimination format being retained for this race.
Daniel Ricciardo's Red Bull was best-of-the-rest, nearly three tenths clear of the Williams of Valtteri Bottas.
The second Williams of Felipe Massa was just 0.002s down in seventh, while Nico Hulkenberg's Force India completed the top eight.
Romain Grosjean's Haas and the two Toro Rossos of Max Verstappen and Carlos Sainz Jr all paid the price for staying in the pits after making single runs in Q2.
Apart from the two Williams drivers, Hulkenberg was the only other driver to attempt two runs in this segment and his second flier was enough to lift him to eighth and knock Grosjean out of the final Q3 spot.
The lack of effort to return to the track despite having ample time to do so suggested Haas and Toro Rosso strategically preferred free choice of tyres for the race start, rather than higher grid positions.
Less than three tenths of a second blanketed Grosjean in ninth to Jenson Button in 14th.
Verstappen and Sainz ended up 10th and 11th, ahead of McLaren-Honda rookie Stoffel Vandoorne (who outqualified team-mate Button on his debut), the second Haas of Esteban Gutierrez and Button.
Red Bull's Daniil Kvyat endured another disappointing qualifying session, ending up 15th in a car comfortably quick enough for Q3.
The second Force India of Sergio Perez and the works Renaults of Kevin Magnussen and Jolyon Palmer dropped out in Q1, along with both Manors and both Saubers.
Perez only had time for one run, which proved insufficient to make the cut as others improved.
Pascal Wehrlein put his Manor-Mercedes 16th with a last-gasp effort, which fell less than three tenths shy of being good enough for Q2.
Marcus Ericsson's Sauber was 0.034s slower in 17th, ahead of Perez, Magnussen (who will start from the pitlane after missing the weighbridge in practice) and Palmer.
Rio Haryanto's Manor and Felipe Nasr's Sauber propped up the timesheet.
Both were well adrift of the rest after completing solitary runs and had no time for a second effort.
Nasr's lap was spoiled by a big lock-up under braking at Turn 1, so he ended up slowest.
Pos Driver Car Time Gap
1 Lewis Hamilton Mercedes 1m29.493s -
2 Nico Rosberg Mercedes 1m29.570s 0.077s
3 Sebastian Vettel Ferrari 1m30.012s 0.519s
4 Kimi Raikkonen Ferrari 1m30.244s 0.751s
5 Daniel Ricciardo Red Bull/TAG Heuer 1m30.854s 1.361s
6 Valtteri Bottas Williams/Mercedes 1m31.153s 1.660s
7 Felipe Massa Williams/Mercedes 1m31.155s 1.662s
8 Nico Hulkenberg Force India/Mercedes 1m31.620s 2.127s
9 Romain Grosjean Haas/Ferrari 1m31.756s -
10 Max Verstappen Toro Rosso/Ferrari 1m31.772s -
11 Carlos Sainz Toro Rosso/Ferrari 1m31.816s -
12 Stoffel Vandoorne McLaren/Honda 1m31.934s -
13 Esteban Gutierre Haas/Ferrari 1m31.945s -
14 Jenson Button McLaren/Honda 1m31.998s -
15 Daniil Kvyat Red Bull/TAG Heuer 1m32.241s -
16 Pascal Wehrlein Manor/Mercedes 1m32.806s -
17 Marcus Ericsson Sauber/Ferrari 1m32.840s -
18 Sergio Perez Force India/Mercedes 1m32.911s -
19 Jolyon Palmer Renault 1m33.438s -
20 Rio Haryanto Manor/Mercedes 1m34.190s -
21 Felipe Nasr Sauber/Ferrari 1m34.388s -
22 Kevin Magnussen Renault 1m33.181s -