The Flying Finn, who joined reigning constructors' champions Mercedes from Williams in January as a replacement for retired world champion Nico Rosberg, produced a final lap of 1:28.769 during an intriguing Q3 top-10 shootout at Sakhir's International Circuit. His Silver Arrows teammate had a late chance to seal top billing for the third time this season, but eventually crossed the line 0.023 seconds off the lead pace.
"I'm really happy," said Bottas, who qualified third for both of his opening races in Mercedes silver. "It's the first pole of my career in my fifth season. It took a few races but I've got it and hopefully it's the first of many.
"Big thanks to the team for giving me this car. We're both starting on the front row and we have done a good job to focus on the evening conditions.
"It's not an easy track to get everything right. It's quite technical and it's easy to have a lock up. It was a good enough lap for pole today."
Hamilton, who made a mistake on his flying lap, was magnanimous in defeat, adding: "Congratulations to Valtteri. He's been working so hard and gelling with the team and today he was just quicker, he did a better job."
Such an impressive performance for Bottas came six days after he cost himself a potential podium place at the Chinese Grand Prix with a silly error. The 27-year-old was backed to recover quickly by Mercedes boss Toto Wolff after spinning behind the safety car on lap six and dropping from fifth to 12th place in Shanghai while trying to maintain tyre temperature. He eventually finished sixth after coming third on his first appearance in the W08 in Melbourne last month.
The Ferraris of joint-championship leader Sebastian Vettel and Kimi Raikkonen were split by Daniel Ricciardo, whose Red Bull teammate Max Verstappen had to settle for P6 and the third row of the grid despite surprisingly setting the pace in the third and final practice session that preceded qualifying.
Nico Hulkenberg secured seventh spot and fellow Renault driver Jolyon Palmer took 10th after reaching Q3 for the very first time. Felipe Massa pipped Romain Grosjean to eighth, while Daniil Kvyat, rookie Lance Stroll, the returning Pascal Wehrlein and Esteban Ocon all fell at the second hurdle. Carlos Sainz, Stoffel Vandoorne, Sergio Perez, Marcus Ericsson and Kevin Magnussen failed to make it out of Q1 and a broken power unit meant that Fernando Alonso could not compete in Q2 and finished 15th without an official time.
The Spaniard has been the talk of the paddock this week after he announced that he would miss May's Monaco Grand Prix in order to compete in the Indianapolis 500. McLaren-Honda have now confirmed that Jenson Button will make a one-off return to F1 for the iconic street race.