Marc Marquez retook the championship lead with his fifth straight Sachsenring MotoGP victory, but he was made to work for it by local hero Jonas Folger.
Though Marquez led away pole, he had to play second fiddle to a charging Folger's Tech3 Yamaha for a handful of laps early on.
Folger had stayed with Marquez and Honda team-mate Dani Pedrosa's initial lead battle, before slicing past both in the opening five laps.
Folger's lead lasted until he outbraked himself at the first corner and allowed Marquez back through.
Another mistake at Turn 1 from Folger later on looked to have settled the lead battle, but Folger continued to hound Marquez until the champion got the hammer down with three laps to go and won by three seconds.
The result means Marquez remains unbeaten at the Sachsenring this decade, having won from pole there every year since coming into MotoGP in addition to his 125cc and Moto2 victories at the track.
Pedrosa drifted away to finish a lonely third.
Following his lacklustre 11th place in qualifying, Yamaha's Maverick Vinales rose into the top six just before half distance.
He then picked off fellow title contenders Valentino Rossi and Andrea Dovizioso to earn fourth.
Aspar Ducati rider Alvaro Bautista flew in the second half of the race to reach sixth behind the two works Yamahas.
Aleix Espargaro also passed Dovizioso to finish seventh for Aprilia, with erstwhile championship leader Dovizioso falling to third in the standings behind Marquez and Vinales.
Folger's team-mate Johann Zarco coming through to ninth from 19th on the grid ahead of Cal Crutchlow.
Jorge Lorenzo, who gambled on soft tyres all around, slumped outside the top 10 by half distance. He finished 11th, a spot ahead of front row starter Danilo Petrucci - who also faded badly.
Andrea Iannone had been battling hard with Lorenzo before a nasty fall in the closing laps.
Sam Lowes also crashed out.
RESULTS - 30 LAPS:
|2||Jonas Folger||Tech3 Yamaha||Yamaha||3.310s|
|6||Alvaro Bautista||Aspar Ducati||Ducati||16.534s|
|9||Johann Zarco||Tech3 Yamaha||Yamaha||21.138s|
|10||Cal Crutchlow||LCR Honda||Honda||24.210s|
|12||Danilo Petrucci||Pramac Ducati||Ducati||31.540s|
|15||Jack Miller||MVDS Honda||Honda||37.771s|
|17||Karel Abraham||Aspar Ducati||Ducati||39.323s|
|18||Tito Rabat||MVDS Honda||Honda||41.190s|
|19||Loris Baz||Avintia Ducati||Ducati||59.850s|
|20||Scott Redding||Pramac Ducati||Ducati||1m01.664s|
|-||Hector Barbera||Avintia Ducati||Ducati||Disqualified|