George Russell claimed the first pole position of his Formula One career for Sunday's Hungarian Grand Prix.
Sainz and Leclerc looked as though they had secured a front-row lockout for Ferrari only for Russell to snatch a shock result with a brilliant final lap at the Hungaroring.
"Come on, whoooo, come on, yes, you beauty, you beauty," said Russell over the radio, unable to hide his delight at his maiden pole and Mercedes' first of the season.
"Amazing. We needed that."
Verstappen locked up at Turn 2 on his opening run in Q3, finishing 1.7 seconds behind, and then reported he had no power as he geared up for his final attempt. "Nothing works," he yelled, unable to improve on his first Q3 attempt.
Mercedes struggled for pace in practice but Russell pulled out one of the laps of his career - finishing eight tenths clear of Hamilton - to take the front spot for Sunday's 70-lap race.
"I am over the moon," said Russell. "That last lap was mega. I came across the line and saw P1 and it was an incredible feeling.
"There are no points for qualifying but we are going to be absolutely going for it. It has been a special day."
Lando Norris took fourth for McLaren, one place ahead of Alpine's Esteban Ocon.
On a poor afternoon for Red Bull, Verstappen's team-mate Sergio Perez took aim at Haas driver Kevin Magnussen after he finished 11th.
Perez claimed the Dane disrupted his speediest lap, saying over the radio: "F****** Magnussen. Yeah I was blocked there by Magnussen."
Sebastian Vettel announced he will bring the curtain down on his Formula One career at the season's final race in Abu Dhabi on November 20.
After winning four consecutive titles for Red Bull between 2010 and 2013 he failed to deliver the championship in a five-season spell before he joined Aston Martin.
But his one-and-a-half year spell with the British team has been disappointing, and there was further woe here when he crashed in final practice.
Vettel worked alongside his mechanics to repair his wounded machine in time for qualifying, but the German failed to make it out of Q1, qualifying 18th.
Nicholas Latifi was the surprise name at the top in Saturday's rain-hit practice but, in the dry, the Canadian finished 20th and last.