Sebastian Vettel claimed pole position for the German Grand Prix, while Formula 1 title rival Lewis Hamilton was only 15th after stopping with a gearbox problem in Q1.
The Ferrari driver held pole position after the first runs in Q3, with all drivers on ultrasofts, but faced a challenge from the remaining Mercedes of Valtteri Bottas on the second runs.
Bottas briefly claimed pole position with a lap of 1m11.416s, helped by a mighty run through the stadium section.
But Vettel, who was faster in the first two sectors before losing a quarter of a second to Bottas in the final sector, did enough to take pole by 0.204s on his final lap.
The second Ferrari of Kimi Raikkonen was third, 0.335s off Vettel, having again looked like a potential threat for pole position.
He made a mistake at Turn 12 on his first run that cost around three tenths after he hit the inside kerb, then couldn't quite find the pace on his second run.
Red Bull driver Max Verstappen was fourth, just under three-tenths behind Raikkonen, and benefitted from the absence of Hamilton.
Hamilton was ordered to stop on his second Q1 run after losing gear selection, which followed immediately after he ran wide in Turn 1.
In rejoining, he struck the rumble strip at the exit of the corner, which kicked the car up and appeared to cause the problem that manifested itself on the run to Turn 2 - although he reportedly subsequently said the problem had appeared before this moment.
Hamilton attempted to get the car back to the pits but eventually stopped at Turn 10 after being ordered to do so by the team.
Currently 15th thanks to setting a time good enough to escape Q1 before the problem, he will move up a place thanks to Daniel Ricciardo's penalties - subject to incurring any grid drops himself.
Haas pairing Kevin Magnussen and Romain Grosjean locked out the third row with fifth and sixth, with the lead Renault of Nico Hulkenberg missing out on splitting the pair by 0.016s.
The second Renault of Carlos Sainz Jr was eighth, ahead of the Sauber of Charles Leclerc and Sergio Perez's Force India.
Fernando Alonso was quickest of those eliminated in Q2 in 11th place, with a gap of six-tenths to Perez ahead in that segment of qualifying.
That put him ahead of Williams driver Sergey Sirotkin, who posted the team's best qualifying result since April's Azerbaijan Grand Prix in 12th place.
Sauber driver Marcus Ericsson was 13th and slowest of those to set a time in Q2 after causing a nine-minute red flag period when he spun into the gravel at the Turn 13 left-hander.
Ericsson was able to dig himself out of the gravel, but in doing so pulled it onto the track and led to the session being stopped two minutes later.
After his second run, the Swede suggested that he lost grip on his final qualifying attempt and speculated he might have sustained some minor damage when he hit a kerb.
Hamilton, thanks to his Q1 failure, and Daniel Ricciardo, who will start from the back anyway thanks to engine component changes, did not run in Q2.
Esteban Ocon was bumped into the dropzone late in Q1 when Force India team-mate Perez improved on his second push lap on his second set of ultrasofts.
Ocon went into qualifying with only one dry free practice session under his belt, having sat out FP1 to allow Nicholas Latifi to drive then been hit by rain in FP3.
Toro Rosso pair Pierre Gasly and Brendon Hartley were 17th and 18th, separated by three-tenths of a second.
Lance Stroll was 19th, while Stoffel Vandoorne's troubled weekend continued as he brought up the rear, two-tenths slower than the Williams driver.
|4||Max Verstappen||Red Bull/Renault||1m11.822s||0.610s|
|8||Carlos Sainz Jr.||Renault||1m12.692s||1.480s|
|10||Sergio Perez||Force India/Mercedes||1m12.774s||1.562s|
|15||Esteban Ocon||Force India/Mercedes||1m13.720s||2.508s|
|16||Brendon Hartley||Toro Rosso/Honda||1m14.045s||2.833s|
|19||Daniel Ricciardo||Red Bull/Renault||1m13.318s||2.106s|
|20||Pierre Gasly||Toro Rosso/Honda||1m13.749s||2.537s|