Lewis Hamilton took a dramatic pole position at the Russian Grand Prix despite coming within a second of qualifying down in 15th.
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.