Felipe Massa took a sensational pole position for Williams at the Austrian Grand Prix as Mercedes duo Nico Rosberg and Lewis Hamilton hit trouble.
Massa heads team-mate Valtteri Bottas in an all-Williams front row with Rosberg third and Hamilton only ninth.
Hamilton ran wide and had his lap discounted on his first run, then spun with an apparent problem on his second.
Ferrari's Fernando Alonso took fourth ahead of Red Bull's Daniel Ricciardo and McLaren's Kevin Magnussen.
Massa's pole was his first for six years as Williams finally delivered on the promise they have shown all season, helped by an untypically messy session by a dominant Mercedes.
Rosberg had been fastest from Hamilton in the second part of qualifying, albeit only by just over 0.1secs from the Williams drivers.
But when it mattered in final qualifying, both Mercedes drivers made crucial mistakes.
Neither of Rosberg's laps were particularly good, but he at least got two in, while Hamilton failed to record a time.
The Englishman was on course to set the fastest time on his first lap but then ran wide at Turn Eight, which drivers had been warned against doing at their briefing on Friday. As a result, his time was disallowed.
Then his rear tyres locked during braking for Turn Two on his all-important final lap.
Initial impressions were that it had not been a driver error - normally it would be the front tyres that locked if the driver had braked too late.
But Hamilton said that while he did not know for sure what had gone wrong because the car was still with officials, he thought he had made a mistake.
"We haven't had the car back yet so I don't know exactly what happened," said Hamilton. "But I assume I just pressed the brake a bit too hard."
Hamilton's troubles have set up a fascinating race but are a potentially significant blow to his title aspirations.
He enters Sunday's race 22 points behind Rosberg in the championship after retiring from a race for the second time this season in Canada last time out and admitted in his BBC Sport column on Friday that he might not be able to afford any more non-points finishes.
Rosberg said: "I definitely didn't expect Williams to be ahead of us. They did a good job but it didn't come off for me today.
"I didn't do that great a lap and then on my final lap Lewis spun in front of me, so I couldn't improve on that lap.
"It's OK to start from third and I still have a quick car."
Problems for Mercedes opened the door for Williams - and both Massa and Bottas seized their opportunity.
The Finn was quicker on their first runs, 0.3secs ahead of Massa with Rosberg in between them.
But Bottas then ran wide through Turns Six and Seven on his final run, allowing Massa to sneak ahead despite a less-than perfect lap.
"It's an incredible moment," Massa said. "It is a long time since I was in this place and hopefully I can be in this place again.
"I am so happy, very emotional. I'm sure Williams feel the same. Williams had an incredible time in the past and they are back to the top."
Bottas said: "It's the best result of my career and I am really happy for the team. The hard work is starting to pay off.
"The race is tomorrow and we need to focus on that. It is not going to be easy to keep the Mercedes behind that's for sure and even some other cars like Ferrari and Red Bull will be fast."
Alonso's fourth place equalled his best grid position of the year and was his highest in the dry all season.
He said: "It was definitely not a normal qualifying and we took advantage of that," adding that the new parts Ferrari had brought to this race, added to the ones tried but not raced in Canada, had been a step forward. "Hopefully we are heading in the right direction."
Team-mate Kimi Raikkonen was eighth, 1.5 seconds adrift after trailing Alonso all weekend and failing to record a decent lap in the final session.
Raikkonen said he had "found it difficult to get a lap together all weekend", and that he had made mistakes braking for Turn One on all three of his laps in the final session.
"It's a disappointing end to qualifying, but that's how it goes," he said.
Ricciardo took fifth but, after his victory in Canada last time out, it was a disappointing performance from Red Bull on their home track
Vettel could not make it into the top 10 shoot-out and qualified 13th fastest at his Red Bull team's own track.
The German will move up a place as a result of a five-place grid penalty for Force India's Sergio Perez, who was 11th ahead of McLaren's Jenson Button.
Perez is being punished for causing the spectacular last-lap collision with Massa in Canada two weeks ago.