Nico Rosberg beats Hamilton to German Grand Prix pole
Nico Rosberg pipped Mercedes team-mate Lewis Hamilton to pole position at the German Grand Prix in a dramatic qualifying session.
Rosberg had to abort his first run in the top-10 shootout because of an electronic error but had the fastest lap of the weekend on his final run.
Hamilton went out to do his final lap afterwards but two errors meant he ended up 0.107secs adrift.
Daniel Ricciardo headed Max Verstappen in an all-Red Bull second row.
The Ferraris of Kimi Raikkonen and Sebastian Vettel were fifth and sixth.
The German Grand Prix is live across the BBC Sport website and 5 live on Sunday at 13:00 BST.
Rosberg beats Hamilton fair and square
Rosberg's pole was his second in a row and his fifth of the season and it is the first time he has beaten Hamilton on merit when the two have been fighting it out in the final seconds of the session.
Of his past four poles, Hamilton was unable to compete in China and Russia because of engine problems, he crashed in the European Grand Prix in Baku after an error-strewn performance and had to back out of his final lap in Hungary last weekend when he came across Fernando Alonso's McLaren, which had spun.
As such, it was a key step for Rosberg, who lost the championship lead to Hamilton for the first time this season following the Briton's fifth win in six races last weekend.
The title rivals are now tied 6-6 on their head-to-head qualifying records this season.
"It is a great feeling," said Rosberg, who said it had been "one of the best laps" of his career, "especially in the circumstances - very, very satisfying".
I also had extra fuel because to make sure I do have another shot, so I had fuel for three laps."
Hamilton said afterwards: "It has been a good weekend. I had no problems. I had the pace but I just didn't finish it off on the last lap.
"Pole was definitely on. I was 0.2secs up on the lap and I just didn't finish it. That's it."
What's wrong with Vettel (and Ferrari)?
Red Bull continued their recent surge in form, which looks as though it could move them ahead of Ferrari as the second team in the championship, and Ricciardo confirmed his position as a qualifying ace.
The Australian edged Verstappen by 0.108secs and has still been beaten only once in qualifying by a team-mate all year.
Ferrari were again disappointing. On a weekend that started with news they had parted company with their highly rated technical director James Allison, Raikkonen was 0.779secs off pole - and 0.173secs ahead of Vettel, who looked out of sorts.
Vettel also incurred the wrath of Alonso, who accused him of holding him up on his final run. Alonso stormed out of the McLaren garage after being knocked out in the second session, which he ended 14th, two places and 0.132secs behind team-mate Jenson Button.
Briton's Jolyon Palmer put in a strong performance to line up 16th, a place and 0.061secs ahead of his more experienced team-mate Kevin Magnussen as both face questions over their futures at the Renault team in 2017.