World champion Casey Stoner mastered a drying track to take pole position for Sunday's German Grand Prix at Sachsenring.
The Australian took top spot with a best time of one minute 31.796 seconds late in the session, which had earlier been hit by heavy rainfall.
The Honda rider's late effort was enough to dislodge the Yamaha of Ben Spies from pole, the American forced to settle for second, around two tenths of a second slower.
Stoner's team-mate Dani Pedrosa took third place in 1min 32.081secs.
Yamaha Tech 3's Cal Crutchlow leads the way on row two, the Briton one place ahead of the second Yamaha of Jorge Lorenzo, who is tied for the championship lead with Stoner on 140 points.
LCR Honda's German rider Stefan Bradl will start sixth, ahead of Ducati's Nicky Hayden, Crutchlow's team-mate Andrea Dovizioso, Valentino Rossi (Ducati) and Aspar's Aleix Espargaro.
The difficult conditions caught out a number of riders, with Michele Pirro, Danilo Petrucci, Mattia Pasini and Hector Barbera all crashing, although none sustained serious injury.