Lewis Hamilton took a dramatic pole position at the Russian Grand Prix despite coming within a second of qualifying down in 15th.
The Briton had no time in the second knockout session when it stopped after Ferrari's Sebastian Vettel crashed.
It was restarted with just two minutes and 15 seconds left and Hamilton made it to the line with a second to spare.
But in the final session Hamilton was flawless as Red Bull's Max Verstappen pipped Valtteri Bottas to second.
Hamilton was 0.652 seconds quicker than team-mate Bottas, while Verstappen took his place on the front row 0.563secs behind the world champion.
Hamilton can equal Michael Schumacher's all-time record of 91 grand prix victories this weekend.
Hamilton described the session as "one of the worst qualifyings - it was horrible, heart in mouth the whole way".
His problems started when he ran wide at the final corner on his first lap in the second session and had what was at the time the fastest lap deleted.
Hamilton asked to stay out and do a second lap, but was overruled and returned to the pits.
He went out for a second run and was three corners from the end of a lap that would again have been fastest when Vettel lost control at Turn Four and spun into the wall, bringing out the red flag with just over two minutes remaining. He will start 15th.
The session was stopped to clear up the debris and repair the barrier, and when it restarted Hamilton found himself eighth in the queue at the end of the pit lane.
He had to overtake a couple of cars to make it to the line in time - and as he slowed at the final corner to give himself some space after failing to pass a Renault into the last corner, his engineer Peter Bonnington was urging him on the radio: "You need to go. Go now."
He crossed the line just before the red lights came on to indicate the end of the session and did a lap good enough for fourth place at the time.
But the drama meant he had to switch to soft tyres rather than the mediums he had been on - a decision on which the team again overruled him. This means Hamilton will have to start on the softs, while Verstappen and Bottas have the mediums, a better race tyre, so Hamilton suspects he will be up against it on Sunday.
After the drama of the second session, Hamilton showed the presence of mind that is one of the many aspects that mark him out as great when he produced a superlative lap at the start of the final session, nearly 0.8secs quicker than Bottas.
The Finn improved on his second run but so did Hamilton and the Briton was in a world of his own.
But as well as his tyre deficit, he is also concerned about the long run down to the first corner, where the pole man is always vulnerable to being slipstreamed.
"I am starting on the soft tyre, which is not good," Hamilton said. "It's nice being on pole but here is probably the worst place to be on pole and undoubtedly I am probably going to get drafted by the cars behind me and they are starting on the medium and that is definitely the better tyre."
Hamilton had also faced a potential penalty for ignoring the race director's instructions when he ran wide at Turn Two in the first qualifying session and not rejoining in the correct manner, but no further action was taken.
Bottas said: "It has been looking pretty good all weekend but Q3 I found some gains but the others found more.
"Here it is pretty sensitive with the tyres getting it right. The first run, the tyres were too cold and the second one, I don't know. It's a pretty good place to start third here and I am on the right tyre as well."
Verstappen's pace was unexpected after Red Bull had appeared to struggle through practice.
"It felt really good," he said. "Just trying to find the right balance. Second run, made a few changes and that gave me more grip. You really need good entry grip on this track and it was a really nice lap to drive."
Verstappen was nearly 1.2secs quicker than team-mate Alex Albon, who qualified 10th.
Racing Point's Sergio Perez took fourth from Renault's Daniel Ricciardo with his final lap, while McLaren's Carlos Sainz was sixth.
The Spaniard's team-mate Lando Norris, using a new nose and front wing, was eighth, while Williams driver George Russell made it into the second session and will start 14th.