Dani Pedrosa beat title rival Jorge Lorenzo by just 0.018s to claim pole position for the San Marino MotoGP at Misano.
After three damp and cold practice sessions, qualifying was dry and bright, with the best lap times of the weekend set from the start of the hour.
A frantic session, as riders sought to make up for the lost track time, ended with Pedrosa jumping from fourth to first with just a few seconds to go, and Lorenzo unable to retaliate on his final lap.
Cal Crutchlow and Stefan Bradl also held provisional pole during the closing stages, but were pushed down to third and fourth as the Spaniards surged ahead.
Pedrosa, winner of the last two races, had been quick from the off, while title leader Lorenzo took longer to get up to speed - the Yamaha rider slotting into second just before the halfway point of the hour.
Soft rear tyres then began shuffling the order, but Pedrosa kept his Repsol Honda on top until Lorenzo jumped ahead on the edge of the last ten minutes.
MotoGP rookie Bradl then bumped Lorenzo to second, the young German keeping his LCR Honda on pole until Crutchlow snatched it from him with three minutes remaining.
The Yamaha Tech 3 rider, who claimed his first MotoGP podium last time at Brno, was then toppled by Lorenzo, before Pedrosa nudged 0.018s ahead of the #99. Lorenzo's last lap was 0.038s from pole.
Pedrosa has closed to within 13-points of Lorenzo with six rounds to go. Both sat out Friday's practice sessions.
Crutchlow claimed his fifth front row of the year, while Bradl will be joined on the second row by Gresini Honda's Alvaro Bautista, another pole sitter during the session, and Valentino Rossi (+0.762s) who is making his final home appearance for Ducati.
Crutchlow's team-mate Andrea Dovizioso was second quickest during the first half of the session, but eventually slipped to seventh, while Lorenzo's factory Yamaha team-mate Ben Spies was likewise an early contender - then suffered a lowside fall on his way to eighth.