It was feared he would be punished for an unsafe release - because his front right wheel was not attached properly - and given a grid penalty, but instead Ferrari were fined €5,000 (RM23,767).
Raikkonen had looked to be faster than Vettel until qualifying but the four-time champion pulled it out when it mattered.
Vettel came closest, posting a time of 1:29:828 on a qualifying simulation lap while Bottas was half a second further back in third.
Hamilton finished second in the Australian season-opener two weeks ago, after storming to pole position.
A mistake at the last corner on his first run in the top 10 shoot-out left Vettel second but a blistering final lap gave him pole ahead of Raikkonen by 0.143secs.More news: Bangladesh observes World Health Day
Hamilton came to Bahrain knowing he was in for a five-place grid penalty for a gearbox change, so he needed to be on his game - with a ideal vehicle - to minimise the damage and give himself the best chance in the race. "First run in Q3 I was very happy and then I tossed it away last corner".
A Mercedes spokesman confirmed Hamilton would have a new gearbox for final practice and qualifying, incurring an automatic five-place penalty.
Lewis Hamilton says Mercedes' failure to out-qualify either Ferrari in Bahrain shows speculation about the team's so-called "party mode" engine setting has been overblown. "My long run I think was okay, it should have been a bit stronger but as I said we try different things with the auto and the balance".
In a further boost for Ferrari, the aging Kimi Raikkonen has looked sharp all weekend, leading the second and third practice.
Friday's practice sessions also offered encouraging signs with Raikkonen heading Vettel in a Ferrari one-two at the top of the time-sheets. Here the track improves all the time, with more grip every lap.More news: Dwayne "The Rock" Johnson Talks Depression, Urges Others to "Open Up"
"On the softs, the auto were much better, but putting the softer compound on, the supersoft, it looks like we're overheating and therefore not extracting the optimum grip". "In clear air we were actually very, very strong", the 28-year-old told reporters.
And the race, scheduled for Sunday, starts at twilight and finishes under lights in order to avoid most of the heat of the day.More news: Where to Find Vending Machines in Fortnite: Battle Royale