Jorge Lorenzo took pole position for Sunday MotoGP race at Jerez after prevailing in a breathless qualifying session on Saturday afternoon.
On a drying track and under leaden skies, the battle for supremacy raged with no fewer than 29 lead changes before the Yamaha rider finally secured top spot with an effort of one minute 39.532 seconds - just 0.135secs clear of fellow Spaniard Dani Pedrosa (Honda).
"We are very happy with this pole position because it was a strange session," said 2010 champion Lorenzo, who leads the early championship standings after his victory at the season-opener in Qatar three weeks ago.
"There were a lot of water patches and it was very dangerous. You had to pay a lot of attention, it would have been easy to crash and get injured.
"Anyway we start in first position so let's see what happens in the race."
American Nicky Hayden took a surprise third place for Ducati, ahead of Britain's Cal Crutchlow, who survived a crash on his way to fourth for Tech 3 Yamaha.
"That was quite an eventful session to say the least and I've got to be happy with fourth position considering I had the crash," said Crutchlow, who finished fourth in Qatar.
"I made a silly little mistake because I hit one of the damp patches and crashed out. It was a high-side but I wasn't even on the throttle.
"But fourth on the grid is not a bad result at all and I am looking forward to the race tomorrow.
"I'm confident I can be fighting to be inside the top five again but I hope it is a full wet or dry race and not mixed conditions."
Reigning world champion Casey Stoner of Australia was fifth on the second Honda, just ahead of the second factory Yamaha of American Ben Spies.
Andrea Dovizioso (Tech 3 Yamaha), Alvaro Bautista (Gresini Honda), Stefan Bradl (LCR Honda) and Randy de Puniet (Aspar Aprilia) rounded out the top 10, while seven-time world champion Valentino Rossi's struggles on his Ducati continued as he finished 13th, over three seconds off pole.