Lewis Hamilton will start the German Grand Prix from 14th on the grid while title rival Sebastian Vettel took a stunning pole position for Ferrari.
Hamilton's Mercedes suffered hydraulic failure in the first part of the session, grinding to a halt on track.
Vettel set pole from Hamilton's team-mate Valtteri Bottas by 0.204 seconds and is now in position to extend his eight-point lead in the championship.
But Bottas' second place gives him a chance to challenge Ferrari.
The Finn edged out Vettel's team-mate Kimi Raikkonen by 0.131secs and has the inside line on the run to the first corner for Sunday's race.
Bottas said: "The start is going to be crucial. Race pace-wise, it is going to be close."
Another blow for Hamilton
Hamilton is consigned to another fightback, but he did not sound optimistic of achieving what he did at Silverstone two weeks ago, when he was punted into a spin by Raikkonen on the first lap but fought back to challenge Vettel for victory in the closing stages.
"It definitely was a tough one. These things happen and all you can do is try to gather your thoughts and put whatever energy you have towards trying to do your best next day. Live to fight another day, another opportunity to rise," Hamilton told BBC Radio 5 live.
"I'll give everything to see how high I can get up but it's not going to be like Silverstone. I am sure I will be able to get through to some point, but to where I don't know."
Hamilton's problem emerged shortly after he had run wide at the high-speed Turn One.
Mercedes team boss Toto Wolff said the problem was "definitely not caused by Lewis' driving". He said that Hamilton suffered a hydraulic leak as he was going over the kerbs at Turn One. This caused a power-steering failure, which caused the car to bounce over the rough ground as he rejoined the track.
He was unable to change gears and was ordered to stop out on the circuit because the problem risked damaging the engine.
It is the latest in a series of blows for Hamilton and Mercedes, after a double retirement in Austria, where they also made a strategic error, and his incident with Raikkonen at his home race.
Ferrari on top
Vettel, who grew up in Heppenheim, less than 30 miles from the track, soaked up the cheers of his home crowd and said he had always felt from his first run in first qualifying that he could take pole.
"Thanks to the fans. It was amazing to see so many Ferrari and German flags," he said. "It just kept getting better and I knew for the last lap I had a little bit more in more. I'm full of adrenaline but so happy."
Raikkonen looked to have the pace to challenge for pole but, as happens so often to the veteran Finn, a mistake in final qualifying affected him.
He ran wide at the fast Turn 12 at the entry to Hockenheim's Stadium section on his first run in the top-10 shootout, clipping the inside kerb and firing across to the outside, where he bounced over the kerbs.
He said the time he lost there meant he had to apply more caution than was ideal to his final lap.
Red Bull's Max Verstappen was fourth after setting the pace in both practice sessions on Friday. He was optimistic then that, on race pace, his team could challenge Mercedes and Ferrari.
Team-mate Daniel Ricciardo starts from the back as a result of grid penalties for using too many engine parts.
Impressive Haas lock out third row
Haas drivers Kevin Magnussen and Romain Grosjean continued their team's recent strong form with fifth and sixth places on the grid, ahead of the Renaults of Nico Hulkenberg and Carlos Sainz, another strong showing from Sauber's Charles Leclerc and Force India's Sergio Perez.
Fernando Alonso gave McLaren their best qualifying performance since Monaco with 11th place, but team-mate Stoffel Vandoorne was last of all, struggling with an unspecified problem with the car.
"He is doing what he can," Alonso said of his team-mate.
"The last two races it seems that car has some kind of performance issue. There is clear signs on the data that there is less downforce on that car. We have been changing some parts and we need to go deep into that investigation."
And there was a chink of light for Williams after a difficult first half of the season. Russian Sergey Sirotkin used a new front wing aimed at solving the car's fundamental aerodynamic inconsistency to qualify 12th. Team-mate Lance Stroll was 19th.