It is Hamilton's first win in Barcelona since 2014 and just the second of the Briton's career at this circuit, closing the gap to championship leader Vettel to just six points. Which augers well for the race.
Russian Grand Prix victor Valtteri Bottas and teammate to Vettel, Raikkonen complete the second row of the grid with the two Red Bull's of Max Verstappen and Daniel Ricciardo, who are still struggling to make significant gains on the top two manufacturers, locked out row three.
Two of the Force India drivers finished in the top ten with Sergio Perez at eighth while another Esteban Ocon ended at tenth, less than a second behind Felippe Massa.
Hamilton eventually stopped at the end of lap 21, taking on the more durable medium rubber, and exited the pit lane almost eight seconds adrift of Vettel.
As for Vettel, the fact that the German even took part in qualifying yesterday was a big deal as his Ferrari auto had a water leak after final practice session and they had to quickly to fit a new engine to his vehicle.
All but three of the last 16 races in Spain have been won from the top slot, leaving Hamilton with every chance of taking his second victory of the season on Sunday to cut Vettel's 13-point lead.
The victor of last year's race and the youngest ever driver to claim a grand prix victory, Red Bull's Max Verstappen, qualified in fifth ahead of team-mate Daniel Ricciardo.
Hamilton's pole also owed a lot to a major upgrade the team brought to the race, with a narrower nose cone and major aerodynamic changes around the front of the vehicle.
Ferrari's updates were less radical, centered on the front wing, bargeboards and brake ducts.
Hamilton topped Q1 comfortably but in Q2, on the soft tyres with which they will start the race, he was only eight-hundredths quicker than Vettel.
Vettel's vehicle needed an engine change between final practice and qualifying, and he praised his mechanics for their efforts in getting it all done with minutes to spare.
Ferrari were the first to blink as Vettel came in for his first stop at the end of lap 14.
Mercedes AMG F1's Lewis Hamilton will begin the 2017 Spanish Grand Prix from pole position. Vettel had not felt comfortable in his auto during the Friday sessions but found his rhythm on the last practice run.
"I struggled for whatever reason to put a decent lap, all the corners together in qualifying".