The Briton, lying second to Vettel in the world championship, finished 0.179s behind the German and a couple of tenths ahead of team mate Valtteri Bottas, though in truth neither Silver Arrow seemed truly in the hunt for pole.
The Red Bulls of Daniel Ricciardo and Max Verstappen were next up in fourth and fifth, the Australian pipping his team mate at the death after gratefully picking up a tow from a recovering Raikkonen.
Completing the top 10 in what was a thrilling session were the resurgent Force Indias of Esteban Ocon and Sergio Perez, making their first Q3 appearances of the year, and the Renaults of Nico Hulkenberg (who entered qualifying with a five-place grid drop hanging over him) and Carlos Sainz.
Q1 began with drama almost from the off. The session was barely four minutes old when Romain Grosjean become the first casualty. A huge lock-up at Turn 3 forced him to take the escape road, causing a big flat spot on his front-left tyre – and ultimately a gearbox issue ended his day before it had even properly begun.
As has been the pattern this season, Raikkonen started the qualifying process in impressive fashion and was the better of the two Ferraris at the beginning of Q1.
With all 10 constructors running on the quickest ultrasoft tyres early on, Force India continued to show signs of improvement with Ocon temporarily going P2 ahead of Mercedes and Red Bull.
But the big talking point of the opening session was a near calamitous moment for Toro Rosso pair of Pierre Gasly and Brendon Hartley. The duo were lucky not to become embroiled in a major accident when a slow-moving Hartley limped out of Turn 14 with a puncture and was almost collected by an onrushing Gasly.
That incident ultimately spelled the end for Toro Rosso, who were followed into Q1 elimination by McLaren's Stoffel Vandoorne, Sauber's Marcus Ericsson - the only driver to fail to reach Q2 this season - and Grosjean. On a positive note, rookies Charles Leclerc and Sergey Sirotkin moved into Q2 for the first time this year.
The second segment saw the top three teams – Ferrari, Mercedes and Red Bull – send all their drivers out on supersoft rubber with an eye on tomorrow's race, while the rest of the field emerged on ultrasofts.
And, similar to the opening session, it didn’t take long for the tricky corners to bring out the best and worst of the drivers.
Raikkonen suffered most after making a costly mistake and flat-spotting his tyres, forcing him to retreat to the pits for ultrasofts - a switch that will surely compromise him in the race when those in front of him will all start on more durable supersoft rubber.
The Finn did at least put the his purple-marked tyres to good use, ending the session just over a tenth quicker than Hamilton as Williams duo Lance Stroll and Sirotkin, along with McLaren's Fernando Alonso, Sauber's Leclerc and Haas's Kevin Magnussen (whose car lost bodywork at one stage) were the unfortunate drivers not to reach Q3.
The final session promised a great showdown, but who would come up with the goods? Ferrari laid down the gauntlet when Vettel produced a superb lap to move to the top, an impressive 0.342s ahead of Hamilton.
And with the German fluffing his final lap, Raikkonen making an error and both Mercedes and Red Bull lacking that extra bit of pace, that lap would ultimately prove enough for Vettel to secure his first hat-trick of pole positions since 2013. No wonder he'd later say 'the car was on fire!'
With the first four on the grid lining up in championship order and major gusts predicted to hit Baku on Sunday, the stage is set for what promises to be a thrilling Grand Prix.
The key quote
"The good point is that our car was really good this afternoon so it should be in a good place tomorrow. Yesterday I struggled a bit with confidence and trust in the car and rhythm but today, when it clicks, it just keeps coming." - Sebastian Vettel
The key stats
- Vettel's pole was his third in a row - the first time he has achieved that feat in this turbo hybrid era (last time: Italy, Singapore, Korea 2013)
- Hamilton will start a Grand Prix on the front row for the first time since the season-opening race in Australia
- Indeed, Hamilton managed to out-qualify Mercedes team mate Bottas for only the second time in the last six races
- Raikkonen's sixth place is his worst-ever start in Baku, and the first time this season that he isn't second on the grid
- Ricciardo and Verstappen have now out-qualified each other at alternating races in 2018
- Ocon has given Force India their best starting slot of 2018 with seventh place - it was also the first time this season that both their cars reached Q3
- Rookies Sirotkin and Leclerc progressed to Q2 for the first time in their F1 careers
- Williams ended their streak of back-to-back Q1 eliminations with both cars. Stroll will start in tenth following Hulkenberg's five-place grid penalty
Onboard pole lap
Sunday's race begins at 16:10 local time (12:10 UTC) with the weather expected to be sunny but windy.