A downpour in the final stages of free practice four left the circuit saturated for the first qualifying segment, although conditions mercifully proved to be easier for the pole shoot-out.
Q1 pacesetter Petrucci used his knowledge of the damp conditions to go top of the pile by 1.7 seconds in the opening stages of the second session, setting provisional pole with a 1m27.815s with eight minutes on the clock.
The Italian, vying for his maiden pole position, then knocked more time off his best with a 1m27.462s.
Motorcycling
Rossi announces decision to retire at end of season
05/08/2021 AT 14:45
But Marquez had other ideas and pipped him by 0.019s with just two minutes left. Petrucci set the timing screens alight on his final attempt, but could do nothing to stop Marquez, who improved on his last tour to a 1m27.302s.
Pole extended Marquez's unbeaten qualifying run at the circuit since his graduation to MotoGp in 2013, and was also his eighth-successive pole in any of the MotoGP categories.
Honda team-mate Dani Pedrosa completed the front row, half a second further back in third.
Cal Crutchlow, who was second in the flag-to-flag race at the Sachsenring last year, heads the second row, with home hero Jonas Folger and Ducati rider Jorge Lorenzo alongside for company.

Marc Marquez (Honda HRC) - Grand Prix of Germany 2017

Image credit: Getty Images

Pol Espargaro pipped brother Aleix to seventh by 0.124s to secure KTM's best qualifying result of the year, the Spaniard coming through Q1 along with Petrucci.
Both factory Yamaha riders struggled in the wet on Friday, and were no threat for the front row a day later.
A late switch to a medium rear wet tyre in the drying condition allowed Valentino Rossi to go ninth quickest with a 1m28.669s.
Team-mate Maverick Vinales was lucky to come away unscathed from early contact with Marquez at Turn 2, but could only manage 11th at the chequered flag.
The Spaniard will start between championship leader Andrea Dovizioso (10th) and Aspar's Alvaro Bautista.

Marc Marquez (Honda HRC) - Grand Prix of Germany 2017

Image credit: Getty Images

Marc VDS' Jack Miller was sat in a Q2 spot as rain started to fall harder at the end of the first session, but was denied at the death by a 1m27.695s from KTM's Espargaro.
The Australian will head the fifth row from Loris Baz and the second KTM of Bradley Smith.
Suzuki's Andrea Iannone struggled in Friday's wet session, but was a contender for a Q2 placement until the closing minutes when he plummeted to 16th.
Assen pole man Johann Zarco came unstuck in the wet weather in Q1 and will start from 19th, his worst qualifying result of his rookie campaign.
The rain also proved problematic for Scott Redding, the Pramac rider failing to replicate his wet weather pace at Assen a week earlier as he qualified 23rd ahead of Tito Rabat - who only missed out on a Q2 spot by a tenth of a second in the dry third practice.
Motorcycling
Savadori to take over from Smith for Aprilia in last three MotoGP rounds
27/10/2020 AT 16:12
Motorcycling
Valentino Rossi tests positive for Covid-19
15/10/2020 AT 17:16