Sebastian Vettel will head an all-Ferrari front row at the Bahrain Grand Prix as Lewis Hamilton will start ninth after a grid penalty.
Hamilton qualified fourth behind Vettel, Kimi Raikkonen and his team-mate Valtteri Bottas but has a five-place drop for an unauthorised gearbox change.
The star of qualifying was arguably Pierre Gasly in the Toro Rosso, who qualified sixth behind Red Bull's Daniel Ricciardo.
Gasly's performance was embarrassing for McLaren, who are down in 13th and 14th.
- Monaco wants to bring back 'grid girls'
- Formula 1 bosses aim for 2021 budget cap
- Bahrain Grand Prix: Your podium predictions
Ferrari on fire
Ferrari have looked to have an edge on Mercedes all weekend, Hamilton and Bottas battling inconsistent handling on the stop-start Sakhir circuit in the desert south of the Bahraini capital Manama.
Mercedes got closer in qualifying than they looked like they might at one point but Vettel was still 0.166 seconds quicker than the fastest Mercedes of Bottas.
Raikkonen had looked to be faster than Vettel until qualifying but the four-time champion pulled it out when it mattered.
A mistake at the last corner on his first run in the top 10 shoot-out left Vettel second but a blistering final lap gave him pole ahead of Raikkonen by 0.143secs.
"It was quite intense," Vettel said. "First run in Q3 I was very happy and then I tossed it away last corner. Really happy I got the second run and got it clean. The car was excellent all weekend so far."
Why was Hamilton slow?
Hamilton knew before coming to Bahrain that he would have a grid penalty and that his job in qualifying was to minimise the damage to his hopes in the race.
But he could only manage fourth, failing to improve his time on his final lap and leapfrogged by Bottas.
From ninth on the grid, he faces a long, hard race trying to get on to the podium.
But he has been helped by a mistake by Max Verstappen, who crashed his Red Bull in first qualifying and will start 15th. That is one less fast car in Hamilton's way as he attempts to make ground.
"The Ferrari was quicker today," said Bottas. "We made some good progress through the weekend. We tried some things that didn't work which is why the gap was sometimes bigger. The set-up was right. Hopefully Lewis can come through the field."
Gasly humiliates McLaren
Gasly was just 1.371secs off pole in the Toro Rosso, a spectacular performance from the Frenchman, who is in his first full season in F1 after being drafted in towards the end of last season.
He headed Renault's Nico Hulkenberg, separated from his team-mate Carlos Sainz in 10th by Force India's Esteban Ocon. Gasly's team-mate Brendon Hartley qualified 11th.
That put both Toro Rosso ahead of both McLarens, an embarrassing result for the team at the home race of their main shareholders the Bahraini royal family.
McLaren ditched the Honda engine at the end of last season claiming it was holding them back, which leaves the team facing awkward questions about the quality of their car.
Alonso's team-mate Stoffel Vandoorne was 14th, 0.313secs off the Spaniard's pace.
Williams are in even more trouble - Sergey Sirotkin and Lance Stroll were 18th and 20th respectively, a poor result for a once-great team that finished third in the championship as recently as 2015.
Predict who will win in Bahrain
Predict who you think will finish in the top three at the Bahrain Grand Prix