Red Bull's Sergio Perez beat Ferrari's Charles Leclerc to take his first Formula 1 pole position at the Saudi Arabian Grand Prix.
The second Ferrari of Carlos Sainz beat Red Bull's Max Verstappen to third.
Haas driver Mick Schumacher was taken to hospital after a high-speed accident, although the German was uninjured.
- Norman, Mickelson & Saudi money: is golf eating itself?
- How to follow the Saudi Arabian Grand Prix
- Full qualifying results
And Lewis Hamilton had his worst competitive showing in qualifying since 2009 in managing only 16th place.
Qualifying happened against the backdrop of a difficult weekend for F1 following a missile strike against an oil facility just nine miles from the track.
The drivers spent four hours in meetings late into the night on Friday discussing whether it was safe to continue driving before eventually deciding to follow the lead of the Saudi government, which gave them assurances the event was secure.
"We don't want to go into details of what we discussed," Leclerc said. "It was more a matter of coming together as drivers to share our options because it was a tricky moment to say the least.
"It was very useful to speak about this all together. It took quite a bit of time but that's normal in those situations.
"We are here anyway and we have not listen to the people who are taking care of the situation, and trust them."
The qualifying battle
Perez's pole was unexpected to say the least. He is not known as a great qualifier, he beat Verstappen only once in their first season together last year and this achievement came in his 220th grand prix.
But it was well deserved. He had looked closer than usual to Verstappen throughout the weekend but put in what he called the lap of his life to beat Leclerc at the very end of qualifying.
"I could do another 1,000 laps and I could never beat this lap time," Perez said.
The Mexican was 0.261 seconds quicker than world champion team-mate Verstappen, who was down in fourth.
Perez beat Leclerc by 0.225secs, with Ferrari's Carlos Sainz third, 0.177secs behind his team-mate.
Mercedes driver George Russell was sixth as team-mate Lewis Hamilton could manage only 16th.
Leclerc himself had saved his best for last - he improved by more than 0.2secs on his final run to leapfrog himself ahead of Sainz, who had taken provisional pole with his first lap.
"The lap felt good," Leclerc said. "I was very happy with the lap. In the second lap, I just went for it. I definitely did not expect that lap time from Checo and he did an incredible job today."
It sets up an intriguing race, with the Ferraris sandwiched between the Red Bulls at the start, following Leclerc's win in the season-opener in Bahrain last weekend, where Red Bull suffered an agonising late double retirement.
And it came at the end of a crash-strewn session in which there were two red flags, the second one for a massive crash involving Schumacher which caused a stoppage of nearly an hour.
What happened to Hamilton?
Mercedes are not competitive at the moment as they battle with aerodynamic problems in their car but no-one would have foreseen Hamilton's struggles.
Hamilton was only 11th fastest in final practice although felt he had hit on a decent set-up direction, but when it came to qualifying after nightfall he complained of a lack of grip.
"It was looking good in P3," he said. "I tried to progress in a similar direction and maybe went a bit too far and the car was just undriveable, so nervous."
It was his worst performance in terms of outright pace, disregarding technical or other problems, since the 2009 British Grand Prix.
Russell was more than 0.6secs quicker than the seven-time world champion in the first session and made it through to the final top 10 shootout.
But while team boss Toto Wolff said he felt the team were still the third quickest car behind Red Bull and Ferrari, that was not the case, and Ocon snuck in front of him.
The second Alpine of Fernando Alonso, Alfa Romeo's Valtteri Bottas, Alpha Tauri's Pierre Gasly and Haas driver Kevin Magnussen completed the top 10.
Lando Norris qualified 11th for McLaren, while his team-mate Daniel Ricciardo was one place behind him but given a three-place penalty for impeding Ocon.
Two big crashes
Schumacher was ahead of Magnussen early in the second part of qualifying but he pushed too hard through the fast swerves for Turns Eight and Nine, caught the kerb, spun and smashed into the wall.
The Haas was badly damaged but Schumacher was conscious throughout and the first indications were that he was uninjured, but he was air-lifted to hospital for precautionary checks.
Schumacher, however, will not take part in Sunday's race after the team withdrew his car.
The accident has raised further questions about the safety of the track, about which drivers have been concerned since it made its debut last year.
The first heave accident happened in the first session, when Nicholas Latifi lost his Williams on the entry to Turn 13. The impact was less severe, and he hit crash barriers rather than an exposed concrete wall and the session was able to resume after a few minutes.