Hamilton and Romain Grosjean of Haas were two of several drivers who rode their luck on the challenging Baku circuit's narrow bends, while Jolyon Palmer's misfortune continued as his auto caught fire.
He improved from sixth to fourth but could not match team-mate Kimi Raikkonen, who will start third on Sunday, and finished more than a second adrift of Hamilton.
Bottas set the early pace on the soft tyre, heading Raikkonen by nearly four tenths of a second.
"There are concerts at every race", Hamilton said.
"Disappointing. I was going for the pole, but the lap at the end just wasn't quite that flawless", Bottas admitted.
Ricciardo's crash with just three minutes on the clock then threatened to scupper Hamilton's chances as all cars were forced to return to the pits, but he picked up where he left off on hi final set of supersofts and, despite Bottas posting his own improvement, Hamilton beat the Finn by almost half a second. "A lot of pressure".
"My first run in Q3 was actually really good, but I was a bit greedy into the last corner, locked up and cost myself time".
Mercedes driver Lewis Hamilton of Britain, left and Mercedes driver Valtteri Bottas of Finland walk between their cars following the qualification at the Formula One Azerbaijan Grand Prix in Baku, Azerbaijan, Saturday, June 24, 2017.
"We have been struggling to get temperature into the front tyre and we didn't know if it was a one lap tyre. I think I had the rhythm at the end but just didn't get everything right", Vettel said.
Alonso is set to drop to the rear of the grid thanks to his 40-place grid penalty for various engine component changes.
The four-time champion was hauled back into the Ferrari garage with just half of the one-session completed, and he did not re-emerge. We were struggling yesterday but we made a lot of changes overnight. At the end I was alone and had no tow in the last sector. I don't have excuses, I could have done better.
Alonso will start in an embarrassing 16th and Vandoorne next to last in 19th.
"I was so disappointed because I know you need to be ideal to win this title". "I am just thankful I was able to pull a lap together", continued the Brit.
The Englishman, who crashed on Friday, is without a point this season and has had to field questions all weekend about what to appears to be his precarious Renault future. The start of my qualifying session was a bit slow, then by Q2 I think I had the auto under control.