Venezuelan Pastor Maldonado will start Sunday's Spanish Grand Prix on pole position for Williams after Lewis Hamilton was sent to the back of the grid because McLaren failed to put enough fuel in his car.
The four race stewards excluded Britain's 2008 world champion from Saturday's qualifying results at the Circuit de Catalunya but allowed him to start from 24th and last place.
Without the most basic human error so far in a season full of pitlane blunders, McLaren would have been celebrating their 150th pole in Formula One.
Instead, the sensational and surprisingly harsh decision - announced four and a half hours after the track action had finished - handed former champions Williams their first pole since 2010 and only their second in six years.
It also promoted Ferrari's local favourite Fernando Alonso to the front row for his home race at a circuit where the winner has started in the top two on 20 of 21 occasions and he can count on near-total support from the crowd.
"It's a great moment for the team and for me. And it's the best present ever for Frank Williams," declared Maldonado, who had earlier attended a 'surprise' 70th birthday bash in the paddock for his team founder.
"I hope to have a great race tomorrow. I'll do my best, we'll see. We have everything and I think the team must be ready for all the situations in the race," he said of his first pole position and first by a Venezuelan.
"But the motivation is there, the mechanics are ready, we're all ready."
Hamilton had been told his car had a problem and was ordered to stop immediately by the team on his slowing down lap after the chequered flag, which the Briton did, rather than drive back to the pit lane.
The governing International Automobile Federation (FIA) said McLaren had breached the technical regulations.
"A team member had put an insufficient quantity of fuel into the car thereby resulting in the car having to be stopped on the circuit in order to be able to provide the required amount for sampling purposes," a statement said.
"As the amount of fuel put into the car is under the complete control of the competitor the stewards cannot accept this as a case of force majeure... the competitor is however allowed to start the race from the back of the grid."
McLaren team boss said Hamilton's car had about 1.3 litres of fuel left in it when stopped. The rules say the car must have a litre remaining once back at the pits for a sample to be extracted.
Hamilton, runner-up in Barcelona last year, had described his pole lap as "one of the best I've ever had" immediately after the session.
Maldonado, who had rocketed to the fastest time in the second session and had been fast all weekend, can become the fifth different winner in five races if he can hold off Alonso and the rest.
"We have been working so hard trying to understand these tyres and to develop our car around these tyres. We made a very good step forward for this race," he said.
Red Bull's double world champion and series leader Sebastian Vettel moved up to seventh place, even though he did not set a lap time in the final session.
"Ultimately Sebastian didn't have great one-lap pace this afternoon, maybe it was the wind, but you have to look at it two ways," said team principal Christian Horner.
"Going into the race with four new sets of tyres is an advantage. Mark (Webber) has four sets of new tyres and Seb has used one more set effectively so F1 is a strategic game."
Vettel's Australian team mate Webber saw his hopes of a third Spanish pole in a row disappear when he failed to make the cut for the final session and qualified 12th, moving up to 11th.
Hamilton's team mate and 2009 world champion Jenson Button will now start 10th.
"I don't know where it went wrong. All day I've struggled with balance," said Button who was fastest in Friday practice.
Romain Grosjean and Kimi Raikkonen now start third and fourth for Lotus with Mexican Sergio Perez fifth for Sauber. Nico Rosberg is sixth for Mercedes, with team mate Schumacher up to eighth.
At the slow end of the pack, Indian Narain Karthikeyan's fate was left in the hands of race stewards after failing to qualify for HRT with the required lap time.
They were kinder to him than Hamilton, deciding to let him race because he had been quick enough in final practice.