Ferrari's Formula One leader Charles Leclerc performed under pressure to come back from a spin with a stunning lap that sent him from 10th to pole position for Sunday's Spanish Grand Prix.
Main rival and reigning world champion Max Verstappen, who had looked like taking the top slot for Red Bull, had to settle for second after a late loss of speed wrecked his final effort at the Circuit de Catalunya.
Leclerc's lap of one minute 18.750 seconds was just over three tenths of a second quicker than Verstappen's best with the top two continuing a battle that has been the talk of the season.
"I had (some) moments on my lap but at the end I made it stick and I'm very, very happy with pole position," said Leclerc.
Ferrari's home hero Carlos Sainz secured third place, but 0.416 slower than Leclerc, with George Russell taking the fourth slot for a revived Mercedes team enjoying their best Saturday of the campaign so far.
Russell's team mate and seven-time world champion Lewis Hamilton qualified sixth, behind Red Bull's Sergio Perez. The Briton has won the last five Spanish Grands Prix and six in total but that run now looks likely to end.
The pole was Leclerc's fourth in six races and second in succession.
Verstappen, who has won the last two races to close the championship gap to 19 points, complained over the radio of a problem at the key moment.
"I couldn't do my final run. I had a DRS (drag reduction system that) didn't open or I just lost power, so it's a bit of a shame," said the Dutch driver, who took his first win in Formula One at the circuit in 2016.
"To be on the front row for us here, looking at the whole weekend so far, it was a good achievement. But, of course, I would have liked to go for that final run."
DRS ISSUE
Team boss Christian Horner later confirmed a DRS issue and said the engine was fine.
Sainz, who has yet to win in Formula One but will be cheered on by a capacity crowd after two years of pandemic-related restrictions, said everything was still possible.
"Conditions haven't been the easiest with the heat, with the wind, but today we managed to put in a decent lap which means we can fight tomorrow," he said.
McLaren's Lando Norris had looked set to make the top 10 but had his best lap time deleted in the second session for exceeding track limits, allowing Haas's Mick Schumacher to leapfrog ahead and qualify 10th.
Schumacher's team mate Kevin Magnussen will start eighth, with McLaren's Australian Daniel Ricciardo ninth.
Both Aston Martins went out at the first hurdle despite an eye-catching update package that drew accusations of copying from Red Bull.
Four-time world champion Sebastian Vettel starts 16th and Canadian team mate Lance Stroll, son of the team's billionaire owner Lawrence, qualified 18th.
Twice world champion Fernando Alonso, the only Spaniard to win his home race, will start a disappointing 17th for Renault-owned Alpine.
The winner at the Circuit de Catalunya has come from pole position 23 times in 31 races.