Nico Rosberg will start his home German Grand Prix from pole position, coming back from "an electronic error" to pip Mercedes team-mate Lewis Hamilton.
Rosberg had been fastest in all three practice sessions and was quickest in qualifying, but had to overcome adversity to ensure he would lead Sunday's race at Hockenheimring from the start of the grid in dramatic fashion.
Red Bull duo Daniel Ricciardo and Max Verstappen will start third and fourth respectively, with Ferrari pair Kimi Raikkonen and Sebastian Vettel on the third row.
Toro Rosso driver Daniil Kvyat went out in Q1, while Jenson Button out-qualified Fernando Alonso, though neither McLaren driver was able to replicate their top-10 start in Hungary as they exited in Q2.
Nico Rosberg was on a fast lap at the start of Q3 but bailed out in the closing stages, diving into the pits as Hamilton took provisional pole with a time of one minute and 14.486 seconds.
The German had enough time to get back out for a second run, though, showing tremendous composure as he made time in every sector to secure an advantage of 0.123secs over his team-mate.
Hamilton - who avoided a grid-penalty for an unsafe release in FP3 - managed to close the gap, but a lock-up heading into the hairpin at turn six cost valuable time and consigned him to second.
Ricciardo was slower than Verstappen in Q2 but mounted an impressive response to finish ahead of his team-mate, the two Ferraris trailing them.
Force India pair Nico Hulkenberg and Sergio Perez were split by Williams' Valtteri Bottas in eighth, while Felipe Massa completed the top 10.
1. Nico Rosberg (Mercedes) 1:14.363
2. Lewis Hamilton (Mercedes) +0.107secs
3. Daniel Ricciardo (Red Bull) +0.363s
4. Max Verstappen (Red Bull) +0.471s
5. Kimi Raikkonen (Ferrari) +0.779s
6. Sebastian Vettel (Ferrari) +0.952s
7. Nico Hulkenberg(Force India) +1.147s
8. Valtteri Bottas (Williams) +1.167s
9. Sergio Perez (Force India) +1.174s
10. Felipe Massa (Williams) +1.252s