Ferrari's Kimi Raikkonen narrowly beat home hero Fernando Alonso to pole position in an extremely close qualifying session for the Spanish Grand Prix.
Felipe Massa had to settle for third on the grid in the second Ferrari after holding provisional pole following the first Q3 laps, while Lewis Hamilton and Heikki Kovalainen ended up only fifth and sixth for McLaren, behind Robert Kubica's BMW.
Raikkonen had been fastest by over half a second in Q1, but a poor first Q3 lap left him a provisional fifth on the grid, half a second slower than Massa.
But the Brazilian then failed to improve on his second flying lap, and was knocked off the top spot by Alonso - showing superb form in the revised Renault.
The home crowd seemed set to celebrate a shock pole position for their hero, only for Raikkonen to improve by a second on his final lap and beat Alonso to pole by 0.091 seconds.
Kubica came close to taking third from Massa, lapping just 0.007 seconds behind as he claimed the outside row two spot and pushed Hamilton back to fifth place. Just over 0.2 seconds covered the top five.
Kovalainen was sixth, ahead of Red Bull's Mark Webber and Toyota driver Jarno Trulli.
Nick Heidfeld could only manage ninth in the second BMW, half a second slower than Kubica.
Alonso's teammate Nelson Piquet completed an extremely encouraging session for Renault by making it into Q3 for the first time in his Formula One career. He will start 10th.
Honda narrowly missed out on the top ten start that had been their target for this weekend. Rubens Barrichello came within 0.065 seconds of making it through to Q3 but will have to start 11th, with teammate Jenson Button taking 13th.
They were split by Kazuki Nakajima, as the Japanese rookie outqualified his Williams teammate Nico Rosberg for the first time. The German driver was 0.2 seconds slower in 15th position, behind Toyota driver Timo Glock.
Toro Rosso's Sebastien Bourdais made his second consecutive Q2 appearance and claimed 16th, having beaten teammate Sebastian Vettel by 0.6 seconds in Q1. Vettel was eliminated in the first session and will start 18th.
David Coulthard failed to get beyond Q1 again. Traffic on the Red Bull driver's out-lap prevented him from getting his tyres fully up to temperature and he could only manage 17th.
Despite breaking into the top ten in Friday practice, Force India continued to struggle in qualifying. Giancarlo Fisichella beat Adrian Sutil by 0.7 seconds as they took 19th and 20th.
Unsurprisingly given their difficult build-up to the weekend, Super Aguri remained on the back row of the grid, with Anthony Davidson taking 21st ahead of teammate Takuma Sato.
Pos Driver Team Q1 Q2 Q3 Laps 1. Raikkonen Ferrari 1:20.701 1:20.784 1:21.813 17 2. Alonso Renault 1:21.347 1:20.804 1:21.904 18 3. Massa Ferrari 1:21.528 1:20.584 1:22.058 16 4. Kubica BMW Sauber 1:21.423 1:20.597 1:22.065 13 5. Hamilton McLaren-Mercedes 1:21.366 1:20.825 1:22.096 14 6. Kovalainen McLaren-Mercedes 1:21.430 1:20.817 1:22.231 15 7. Webber Red Bull-Renault 1:21.494 1:20.984 1:22.429 19 8. Trulli Toyota 1:21.158 1:20.907 1:22.529 19 9. Heidfeld BMW Sauber 1:21.466 1:20.815 1:22.542 20 10. Piquet Renault 1:21.409 1:20.894 1:22.699 18 11. Barrichello Honda 1:21.548 1:21.049 12 12. Nakajima Williams-Toyota 1:21.690 1:21.117 15 13. Button Honda 1:21.757 1:21.211 12 14. Glock Toyota 1:21.427 1:21.230 16 15. Rosberg Williams-Toyota 1:21.472 1:21.349 15 16. Bourdais Toro Rosso-Ferrari 1:21.540 1:21.724 15 17. Coulthard Red Bull-Renault 1:21.810 6 18. Vettel Toro Rosso-Ferrari 1:22.108 10 19. Fisichella Force India-Ferrari 1:22.516 11 20. Sutil Force India-Ferrari 1:23.224 8 21. Davidson Super Aguri-Honda 1:23.318 9 22. Sato Super Aguri-Honda 1:23.496 9 All timing unofficial