Championship leader Jorge Lorenzo left it late to set pole position for Sunday's Aragon MotoGP in Spain.
The Yamaha rider posted a time of one minute 49.404 seconds to usurp title rival Dani Pedrosa (Repsol Honda) in the final moments of the qualifying session.
Pedrosa recovered from an earlier crash to sit atop the timesheets as the clock ticked down, but he was unable to respond to the late charge of Lorenzo, who pipped his fellow Spaniard by just 0.088secs.
"I am happy that the bike got better each time we took it out," Lorenzo said.
"We went for it on slick tires at the end and managed to get the first spot."
With five races remaining, Lorenzo leads the way in the standings by 38 points from Pedrosa, who is bidding to bounce back from the disappointment of crashing out in Misano a fortnight ago.
Conditions at Aragon this week have been very similar Misano, with the first three practice sessions held in the wet before the weather cleared for qualifying.
The change in conditions appeared to catch out Pedrosa when he crashed just five minutes into the hour-long qualifying session.
Pedrosa took a heavy tumble when he lost the front of his bike as he braked for turn 14, and returned to the pits for his spare bike and leathers before punching in a solid time that puts him on Lorenzo's shoulder for the start of Sunday's race.
"It's a very good result for us after all the issues we had," said Pedrosa.
"I'm really happy to be on the front row and so close to the pole position.