Lewis Hamilton said his heart was in his mouth as he survived a major scare to put his Mercedes on pole for Sunday's potentially historic Russian Grand Prix.
The British driver will start at the front of the grid in Sochi as he attempts to equal Michael Schumacher's victory record with his 91st career triumph.
But Hamilton came within a single second of qualifying only 15th here after his afternoon was plunged into jeopardy following Sebastian Vettel's crash.
The quadruple world champion's accident at the fourth corner led to the action being halted in Q2 with two minutes and 15 seconds remaining.
Hamilton had failed to post a time – his earlier lap chalked off by the stewards for exceeding track limits.
With Vettel's damaged Ferrari removed, the remaining cars lined up in the pit lane. Hamilton was eighth in the queue ahead of the manic dash to beat the clock.
Leaving the pits, Hamilton ran wide on cold tyres. He was then blocked by Renault's Daniel Ricciardo at the penultimate corner.
Hamilton's race engineer gave his driver the hurry-up.
"Need to go, need to go, need to go," the usually serene Pete Bonnington yelled over the radio, and – with just one second left – Hamilton crossed the line to start a new lap. He finished fourth and a crisis was averted.
A re-booted Hamilton then returned in Q3, posting a dazzling track record at the Sochi Autodrom to obliterate his rivals, finishing more than half-a-second clear of Red Bull's Max Verstappen and six tenths ahead of Valtteri Bottas in the other Mercedes to secure pole 96 of his blockbuster career.
"I had my heart in my mouth the whole way," said Hamilton, 35. "It was one of the hardest qualifying sessions that I can remember. It was horrible.
"Everything was so rushed. There was panic, all sorts of things going on.
"I had to calm myself down, find my centre, calm my heart down. I wanted to deliver in Q3. I was adamant that I had no other choice. I had to deliver on those two laps, and I needed a perfect lap to get the pole.
"We are all under immense pressure and I would say experience helps massively in order to know how to regain your focus."
It marked another hugely-impressive chapter of the Briton's career – one which will see him hang up his crash helmet as the most decorated driver the sport has ever seen.
Hamilton is now expected to reach Schumacher's landmark on Sunday with Russian president Vladimir Putin potentially in town to witness a rewrite of the sport's record books.
But it is unlikely to be straightforward for the six-time world champion who will be on a less-desirable strategy than his rivals.
Hamilton will start on the soft rubber – a cumulative effect of his Q2 drama – while Verstappen and Bottas will be on the more durable tyres.
Hamilton will also be exposed on the 900-metre chase down to the opening corner, the longest run of the year.
"It is not a good place to start," added Hamilton. "There is a greater tow on this year's cars so I expect at least one of Valtteri or Max to come flying by at some point. I am just going to run the fastest race I can.
"We will figure out this evening if there is a different type of race I can do to keep my position."
Hamilton was summoned to see the stewards on Saturday evening for failing to follow the rules when he rejoined the track at the second corner in the opening minutes.
The Mercedes star avoided further action but was told he will be dealt a five-second penalty in Sunday's race if he repeats the same manoeuvre.