Bottas, just a fortnight after his frightening crash with Williams' George Russell in the Emilia Romagna Grand Prix, bounced back from that to claim his 17th pole.
It also came after the Finn's car required the change of a gearbox sensor in the final half-hour in the build-up to qualifying at Portimão.
It is the 71st Mercedes front-row lockout in 141 grands prix in the turbo-hybrid era since 2014.
It proved to be a remarkable top-10 shoot-out as Mercedes went for a second run on medium-compound tyres, believing it to be more suited to its car compared to the softs.
Hamilton had underlined the pace of that tyre by posting a 1:17.968s to comfortably lead the field in Q2, but both he and Bottas were almost four-tenths of a second shy of that time on their first runs in Q3.
There was no improvement, though, on the mediums as Bottas' lap of 1:18.348s was good enough to beat Hamilton by a slender margin.
Verstappen, whose first flying lap in Q3 was deleted for exceeding track limits at turn four and which would have been good enough for pole, will line up third ahead of team-mate Sergio Perez.
The Red Bull duo will start the race on the medium tyre, compared to the Mercedes pairing on the softs, however, there is likely to be concern inside the former team given the lack of pace shown on the yellow-stripe tyre in Q2.
AlphaTauri's Pierre Gasly starts ninth ahead of Sebastian Vettel, who has endured a wretched time so far with Aston Martin, but who reached Q3 for the first time since last year's British Grand Prix.
George Russell produced another staggering qualifying performance as he will start from 11th, his highest grid slot for Williams, missing out on a place in the top 10 by just 0.057s to Gasly.
The Briton will line up ahead of Alfa Romeo's Antonio Giovinazzi and two-time title-winner Fernando Alonso in his Alpine, who finished nine-tenths of a second behind Ocon in Q2.
AlphaTauri's Yuki Tsunoda starts 14th, with Kimi Raikkonen 15th in his Alfa Romeo, leaving the Finn to hope for another spellbinding opening lap as was the case in this race last year when he made up 10 places.
Remarkably, despite declaring after Friday practice that he felt he had taken "a step forward" with the MCL35M, McLaren's Daniel Ricciardo proved to be the big casualty of Q1.
Ricciardo will start 16th after finishing 0.042s behind Russell, and staggeringly over a second adrift of team-mate Norris who set the second-best time of the session.
It is the first time in 25 races, since Japan 2019, Ricciardo has failed to make it out of Q1, with the Australian lining up ahead of Aston Martin's Lance Stroll.
There was also a significant disparity between the Canadian and team-mate Vettel of three-quarters of a second as the four-time champion was seventh fastest in Q1, and despite the former sporting upgrades on his car that are not present this weekend on the latter's AMR21.
Williams' Nicholas Latifi starts 18th, with the back row again occupied by Haas duo Mick Schumacher and Nikita Mazepin who were separated by half a second.
GPFans is a multi-platform, multi-language brand dedicated to Formula One coverage. We bring you all the ins and outs of the sport, 24/7, everything from up-to-the-minute news and features to the latest viral stories and clips.
We believe that a new generation of exciting, outspoken drivers will make F1 more popular than ever before, and we want to give our users access to as much of their heroes as possible, on and off the track. From Lewis Hamilton to Max Verstappen, Daniel Ricciardo to Sebastian Vettel, we provide in-depth analysis of every every Grand Prix in the season, from Australia to Abu Dhabi.
With Formula One under the new ownership of Liberty Media, how the sport is being covered is evolving, and GPFans will look to be at the heart of this progression into new media, as one of the fastest-growing sites covering the king of motorsports.