The Formula One world championship leader clocked 1:16.173 as the top three were separated by barely a tenth of a second, with Mercedes enjoying a front-row lockout.
Vettel, the faster of the two Scuderia cars in both sessions, was 0.95s off the pace in FP1 before improving to 0.326s adrift in the afternoon.
Hamilton hadn't taken pole since the season-opener in Australia.
But the German lost out by 0.132secs on this track that exposes the aerodynamic qualities of a auto like few others.
"We've got much different tyres this weekend, given that there's less rubber on them, so they're feeling just different, sliding a lot more".More news: Traders Look To Replace Iranian Crude Oil As Sanctions Loom Again
Most teams brought significant updates to Barcelona, which marks the beginning of the European season in F1.
Verstappen and Ricciardo, having held second and third after the first runs, were relegated to fifth and sixth.
Alonso's previous best qualifying position this year was 11th and he is now the only driver on the grid to have out-qualified his team-mate at all races so far. His team-mate Stoffel Vandoorne was ninth in the running. The team's miserable session was topped off by Lance Stroll spinning out in the closing seconds of Q1, losing control of his vehicle at Turn 13 and ending up in the wall. Sergei Sirotkin was back in the vehicle for the afternoon run.
Almost every team typically takes this opportunity to introduce a major package of updates to their vehicle.More news: Homeland Security Director Kirstjen Nielsen Nearly Resigns After Trump Blow Up
BBC Sport's Andrew Benson noted some engine concerns for the Scuderia after Raikkonen needed to return to the pits.
"Not entirely happy, but we expected Mercedes to be very strong", Vettel said.
"I ruined by first run in Q3 so I had really one chance in the last run for a decent lap". Obviously we had the change for everyone but I think they are a bit harder, so for me it was pretty straightforward as I said because I was happier with the auto with that tyre.
"Not that any of us are designers, but they haven't asked for our input".
"Right now I think it is important to maximize everything in the race".
"I don't get why, for example, in golf you get all the great golfers who design golf courses, and then you've not got any of the top racing drivers ever in history who ever designed a race track", the four-time world champion told reporters before this weekend's Spanish GP.More news: Paul Casey withdraws from Players Championship with injury