Felipe Massa grabbed his third straight pole to deny home favourite Fernando Alonso at the Spanish Grand Prix.
Massa took his sixth career pole in Barcelona
The Ferrari driver came out of nowhere to lay down a hot lap of one minute, 21.421 seconds, edging out McLaren's Alonso by three hundredths of a second.
Ferrari's Kimi Raikkonen starts on the second row with Lewis Hamilton, whose McLaren topped the practice times.
Alonso, Raikkonen and Hamilton go into Sunday's race in Barcelona tied at the top of the championship on 22 points.
Despite some productive testing in Spain during the month-long break, Ferrari had kept their powder dry in Barcelona - until the dying seconds of qualifying.
The McLaren duo had dominated the practice sessions and Alonso set the pace in the final shoot-out with a lap of 1:21.661.
But after seeing his team-mate Raikkonen push Hamilton into third, Massa delivered a blistering finish to overhaul Alonso for his sixth career pole.
"I just managed to put a lap together with no mistakes and so I'm happy to see the job done for the team," said Massa.
"I am proud, to have three poles in a row, to be really quick and to have a great car.
Ferrari always seem to play games in practice and we just pay no attention to it
McLaren driver Lewis Hamilton
"We're looking forward to having an important and good race."
Alonso, who became the first Spaniard to win the Spanish Grand Prix last year, is ready for a tight race around the Circuit de Catalunya.
"We saw a really close fight and this qualifying is another confirmation between how tight things are between the McLaren and Ferrari teams," said the double world champion.
"The championship and races are so tight that you always have to be 100%, but we're confident."
Hamilton had set the pace in practice, posting the quickest time in Saturday's final session, but the rookie again struggled to convert his speed during qualifying.
The 22-year-old qualified in fourth for the third time this season and knows he has to come out of the blocks fast if he is to keep up his podium run.
Alonso (left) and Hamilton have work to do in Barcelona
"Not to be one and two is a bit of a shame," said Hamilton. "But we have to make sure we do a good job out of the first corner again.
"Ferrari always seem to play games in practice and we just pay no attention to it."
Behind Hamilton come Robert Kubica for BMW Sauber, the Toyota of Jarno Trulli and the second BMW of Nick Heidfeld.
Renaut's Heikki Kovalainen made it through to the top-10 shoot-out for the first time and starts in eighth place just ahead of Red Bull's David Coulthard.
It is the first time Coulthard has qualified in the top 10 since last year's German Grand Prix at the end of July.
There was less luck for team-mate Mark Webber, who starts in 19th after problems with his car's hydraulics.
Britain's Jenson Button starts 14th for Honda ahead of compatriot Anthony Davidson's Super Aguri.
Final grid positions after qualifying in Barcelona:
1 Felipe Massa (Bra) Ferrari 1min 21.421secs
2 Fernando Alonso (Spa) McLaren 1:21.45
3 Kimi Raikkonen (Fin) Ferrari 1:21.723
4 Lewis Hamilton (Gbr) McLaren 1:21.785
5 Robert Kubica (Pol) BMW Sauber 1:22.253
6 Jarno Trulli (Ita) Toyota 1:22.324
7 Nick Heidfeld (Ger) BMW Sauber 1:22.389
8 Heikki Kovalainen (Fin) Renault 1:22.568
9 David Coulthard (Gbr) Red Bull 1:22.749
10 Giancarlo Fisichella (Ita) Renault 1:22.881
11 Nico Rosberg (Ger) Williams 1:21.968
12 Rubens Barrichello (Bra) Honda 1:22.097
13 Takuma Sato (Jpn) Super Aguri 1:22.115
14 Jenson Button (Gbr) Honda 1:22.120
15 Anthony Davidson (Gbr) Super Aguri no time
16 Vitantonio Liuzzi (Ita) Scuderia Toro Rosso no time
17 Ralf Schumacher (Ger) Toyota 1:22.666
18 Alexander Wurz (Aut) Williams 1:22.769
19 Mark Webber (Aus) Red Bull 1:23.398
20 Adrian Sutil (Ger) Spyker 1:23.811
21 Christijan Albers (Ned) Spyker 1:23.990
22 Scott Speed (USA) Scuderia Toro Rosso no time
Follow live coverage of the Spanish Grand Prix on BBC Five Live and the BBC Sport website at 1300 BST on Sunday.