Lewis Hamilton claimed pole position in an unpredictable Spanish Grand Prix qualifying session, but only after bettering shock provisional poleman Pastor Maldonado at the checkered flag.
With teams having concerns over tyres for Sunday, it was unsure how many drivers would emerge for the Q3 shootout.
Hamilton and Nico Rosberg put laps on the board in the middle of the session, before Fernando Alonso put a strong lap together in his Ferrari at his home race to move into P1. Kimi Raikkonen moved into second, only to then be displaced by Sergio Perez. Romain Grosjean then moved ahead of Perez in his Lotus.
Williams driver Maldonado had been fast throughout the qualifying hour, topping the Q2 session. In Q3 he bettered Alonso's time to take provisional pole, by just a couple of hundredths of a second.
It wouldn't quite be a fairytale result for Williams and Maladonado though as Hamilton completed his second run and go half a second clear at the head of the pack.
The 2008 world champion did however fail to make it round his slowdown lap, after the team ordered him to stop the car.
Alonso completed the top three behind Maldonado, with Grosjean, Raikkonen, Perez and Rosberg completing the runners who set a Q3 time. Sebastian Vettel went out twice in his Red Bull but didn't set a lap time on either occasion so is set to start from eighth. Michael Schumacher also opted not to set a time, while Kamui Kobayashi was unable to play a part in the final segment after stopping his Sauber at the side of the track at the end of Q2 having set a time good enough to get through.
There were two big-name casualties at the end of Q2, with Jenson Button and Mark Webber ending up 11th and 12th. Button had been making his rather-too-common complaint on the radio of a lack of grip, while Webber was sat in the garage as others improved and bumped him out of the top ten.
The Force India duo of Paul Di Resta and Nico Hulkenberg will share the seventh row of the grid, with the Toro Rossos of Jean-Eric Vergne and Daniel Ricciardo locking out the eighth row. Felipe Massa ended up with the slowest time in Q2 on another difficult day for the Ferrari man.
While Maldonado put his Williams on the front row, Bruno Senna exited in Q1 when he spun into the gravel at the end of his final lap as he pushed hard to get out of the drop zone. The regular Q1 drop-outs ended up in a slightly unusual order, with Vitaly Petrov outqualifying Caterham teammate Heikki Kovalainen for 19th, and rookie Charles Pic beating his Marussia teammate Timo Glock by half a second for 21st place.
Narain Karthikeyan was three and a half seconds adrift of his HRT teammate Pedro de la Rosa and will need the stewards' permission to race after falling some way outside of the 107% time.