Bottas led a Mercedes one-two in Baku, helped by an interrupted qualifying session that included post-practice favourite Charles Leclerc crashing out in Q2.
Hamilton, who will line up second, said he never recovered from a “pretty shocking” first two corners.
“Valtteri did an exceptional job, it was a great result for us as a team,” he said. “Coming into this weekend it didn’t look like we had the pace. Our race pace looked good but the pace in qualifying didn’t look as close as we’d like to the Ferraris.
“We worked on the car, improved it today. Unfortunately my first two corners were pretty shocking, I had a small moment in Turn 1 and then Turn 2. Already by Turn 4 I think I was three tenths down. I recovered that in the next two sectors but unfortunately it wasn’t enough.”
The Mercedes drivers had trailed Ferrari by more than a second in final practice.
Asked if it was unexpected compared to his first pole of the season in the previous race in China, Bottas said: “You could say so yeah, definitely.
“After the practice yesterday and this morning we definitely saw Ferrari was extremely quick. Also Red Bull was quick. Going into qualifying it felt kind of out of reach, but you never know what can happen so we don’t give up. In the end Charles went off and it was down to one lap at the end.”
Bottas said the constant delays – after Robert Kubica had also crashed in Q1 in similar fashion to Leclerc in Q1 – meant conditions changed throughout qualifying.
Having snatched pole right at the end of Q3, he said: “Because everything was delayed and it was a lot cooler so the tricky bit was to get the tyres to work.
“And when it comes down to one lap on this kind of track the tow effect is quite important. I managed to get a pretty good gap to the car ahead. Also, it feels good to have a good lap when it matters.”