Lewis Hamilton took his first pole position since the opening race of the season as he beat team-mate Valtteri Bottas at the Spanish Grand Prix.
The Mercedes drivers locked out the front row, Hamilton just 0.04 seconds ahead, with Ferrari's Sebastian Vettel in third from team-mate Kimi Raikkonen.
Red Bull's Max Verstappen and Daniel Ricciardo secured the third row.
Fernando Alonso put a McLaren in the top 10 for the first time this season, eighth behind Kevin Magnussen of Haas.
Have the cars' upgrades changed the game?
Vettel has secured the last three pole positions as the Ferrari established itself as the fastest car in the early stages of the new season.
But the German lost out by 0.132secs on this track that exposes the aerodynamic qualities of a car like few others.
It was the first Mercedes one-two of the season, a measure of the world champions' relative struggles to get on top of their new car and the tyres Pirelli has produced for this season.
But Mercedes have looked much more competitive this weekend, where all teams have brought their first major upgrades of the season.
Red Bull's redesign is one of the most dramatic in the pit lane, but it was not enough to allow them to challenge the Mercedes and Ferrari cars, who benefit from an engine boost in the final part of qualifying which Renault do not have.
Verstappen was 0.643secs off pole and just 0.002secs ahead of Ricciardo.
- 'Verstappen's been on the Red Bull naughty step' - Chequered Flag podcast
- Spanish Grand Prix: Can Barcelona provide another thriller?
A huge gap to the rest
There was a huge gap back to the rest of the field, Magnussen more than 0.8secs slower than the Australian as Haas recovered their early season form.
The Dane snuck ahead of home hero Alonso by just 0.045secs but there will be encouragement for McLaren that the major nose redesign they brought here has improved their car.
Alonso's previous best qualifying position this year was 11th and he is now the only driver on the grid to have out-qualified his team-mate at all races so far. Team-mate Stoffel Vandoorne was 11th.
His fellow Spaniard Carlos Sainz was ninth in the Renault, whose other driver Nico Hulkenberg, usually faster, was hampered by a fuel-pressure problem and could manage only 16th.
A big gap back to Williams
When it mattered, the plethora of spins and off-track moments seen in the practice sessions generally stopped, although Lance Stroll crashed his Williams when he ran wide on the exit of Turn 13 and did not lift off.
The Canadian qualified slowest in 19th place, just behind team-mate Sergey Sirotkin, on a dire weekend for Williams that underlined the major problems they have with their car this year.
Toro Rosso's Brendon Hartley missed qualifying after a high-speed crash at Turn Nine in the closing minutes of final practice.
The car was badly damaged and the team were unable to repair it in time. The chassis survived, but it will need a new engine and gearbox for the race.
What they said
Hamilton said: "Very close in qualifying but I'm very happy. I needed this pole, I haven't had a pole for a while."
Vettel, who is four points behind Hamilton in the championship, said: "I was happy with the lap. The first run was not so good, but the last lap I was happy.
"It was feeling good until the end, when I looked up at the tower and my name did not go to the top. But Mercedes have looked strong. I think it will be an interesting race."
Who will win in Spain?
Choose your top three drivers from the list below