Sepang - World championship leader Lewis Hamilton will start from pole position for Sunday's Malaysian Grand Prix with title rival Sebastian Vettel at the back of the grid.
Hamilton had been off the pace all weekend in practice but his Mercedes team turned it around in qualifying on Saturday to head Ferrari's Kimi Raikkonen and the Red Bull of Max Verstappen.
But Vettel's world championship hopes suffered a huge blow when his Ferrari failed to set a time in the first qualifying session, meaning he will start last.
Vettel, 28 points behind Hamilton in the title race, lost drive on his first flying lap.
"It feels like I have no turbo," he said over team radio.
Hamilton was clearly surprised to be on pole after a torrid weekend where he had failed to be quicker than fifth in any practice session.
"We had no idea what was going to happen today," said Hamilton.
"I'm sorry for what happened to Sebastian but somehow we managed to turn it around and it is a real surprise to be up here with these guys.
"I'm very grateful to the team. The car felt good."
With mechanics unable to fix Vettel's Ferrari before the end of Q1 the German will start from the back of the grid unless there are penalties for other drivers.
Vettel's engine had been changed before qualifying after a similar gremlin in final practice Saturday only for the new unit to fail.
"Who knows what will happen tomorrow," Vettel told AFP. "The race is tomorrow not today. We have a very quick car and we saved some tyres.
"If it happened tomorrow it would be more of a problem. Anything can happen -- you saw that in Singapore two weeks ago how everything can change."
In Singapore, Vettel had started from pole only to crash on a rain-soaked first lap as Lewis Hamilton won from fifth on the grid to extend his championship lead.
Results from qualifying for the Malaysian Grand Prix on Saturday:
Lewis Hamilton (GBR/Mercedes) 1:30.076, 2. Kimi Raikkonen (FIN/Ferrari)
1:30.121, 3. Max Verstappen (NED/Red Bull) 1:30.541, 4. Daniel
Ricciardo (AUS/Red Bull) 1:30.595, 5. Valtteri Bottas (FIN/Mercedes)
1:30.758, 6. Esteban Ocon (FRA/Force India) 1:31.478, 7. Stoffel
Vandoorne (BEL/McLaren) 1:31.582, 8. Nico Hulkenberg (GER/Renault)
1:31.607, 9. Sergio Perez (MEX/Force India) 1:31.658, 10. Fernando
Alonso (ESP/McLaren) 1:31.704
Eliminated in Q2:
Massa (BRA/Williams), 12. Jolyon Palmer (GBR/Renault), 13. Lance Stroll
(CAN/Williams), 14. Carlos Sainz Jr (ESP/Toro Rosso), 15. Pierre Gasly
Eliminated in Q1:
16. Romain Grosjean
(FRA/Haas), 17. Kevin Magnussen (DEN/Haas), 18. Pascal Wehrlein
(GER/Sauber), 19. Marcus Ericsson (SWE/Sauber), 20. Sebastian Vettel