The defending three-time world champion, who trails Rosberg by 43 points in the title race, revived his quickest form of the past with a stunning showing in both Q2 and Q3.
He ended up with a best lap in one minute and 22 seconds, 0.280 seconds ahead of Rosberg's fastest lap on a day when teenager Max Verstappen demonstrated just why he was promoted, so unexpectedly, by Red Bull from Toro Rosso.
The 18-year-old Dutchman was second-fastest at one time and his speed inspired his Red Bull team-mate, Australian Daniel Ricciardo, who responded by qualifying third ahead of him on the grid.
This meant the two Red Bulls separated Mercedes from their main rivals Ferrari, who were pushed back to fifth and sixth, Finn Kimi Raikkonen edging ahead of four-time champion Sebastian Vettel in the final seconds.
Hamilton's success brought him his third pole this year, his second in Spain and the 52nd of his career, a feat that left him euphoric as he waved to the crowd afterwards.
"I'm so very, very happy with this," he said. "Nico has been strong here all weekend, but one step at a time, I've been bringing it together. I didn't get to compete in the last two qualifying sessions so this is three out of three for me!"
Rosberg said: "I'm disappointed, but Lewis was just quicker today and that's it. It's the race that counts so I'll try to take my chances."
Finn Valtteri Bottas was seventh for Williams ahead of Spaniard Carlos Sainz in the leading Toro Rosso, Mexican Sergio Perez of Force India and the home hero, two-time champion Fernando Alonso of McLaren Honda.
On a warm day, with an air temperature of 22 degrees and a track temperature of 42 degrees, qualifying delivered an early surprise with the Q1 elimination of veteran Brazilian Felipe Massa of Williams.
Massa had been complaining about his discomfort with the car throughout practice and was unable to deliver a lap that reflected his usual speed.
He went out in 18th place, one behind the Renault of British rookie Jolyon Palmer, but ahead of the two Saubers of Swede Marcus Ericsson and Brazilian Felipe Nasr.
The final two places were filled by the two Manor Racing men, German Pascal Wehrlein and Indonesian Rio Haryanto.
"The team made a big mistake today with the timing and let's hope we don't do it any more," said Massa, his team having chosen to be the last to join the fray, long after the rest had clocked a lap.
Rosberg had been quickest at the front, with a best lap of the weekend until that point, ahead of Hamilton, but the world champion bounced back in Q2 with an emphatic show of his pulverising pace.
Clocking a best of the day in 1:22.159, Hamilton was six-tenths clear of Rosberg with Verstappen, in inspired form, again securing third ahead of Raikkonen, Ricciardo and Vettel.
Behind them, a late lap from Perez lifted him to seventh and eliminated Force India team-mate Nico Hulkenberg out of the top-ten shootout.
Briton Jenson Button took 12th in the second McLaren ahead of Russian Daniil Kvyat, back at Toro Rosso, Frenchman Romain Grosjean of Haas, Dane Kevin Magnussen of
Renault and Mexican Esteban Gutierrez in the second Haas.
Inspired, perhaps, by his home fans, Alonso squeezed through by just 0.011 seconds ahead of Hulkenberg.
The two Mercedes men were first out on track for Q3, Rosberg going quickest on their first runs followed by Hamilton locking up his left front wheel at Turn 10 and running wide when he was three-tenths up on another flying lap.
The Mercedes men were then split by an extraordinary effort from Verstappen, the Dutch teenager showing the raw talent that persuaded Red Bull to promote him from Toro Rosso.
That effort meant he was ahead of every world champion on the provisional grid before the top men prepared for their final flying runs.