The German took his second consecutive pole by 0.254 seconds from Hamilton, with Red Bull's Sebastian Vettel third ahead of Lotus's Kimi Raikkonen.
Gary AndersonBBC F1 technical analyst
It's great to see the two Mercedes on the front row, as they really did concentrate on race running right up until the final 10 minutes of final practice.
I am sure they have improved their race pace - Nico Rosberg did a consistent run on the hard tyre on Friday - but the question is: have they done enough? Both drivers were about 0.3secs quicker than anyone else in sector three, which is all about front end in Turn 12 and traction out of the chicane, but are only as good as anyone else around everywhere else.
Ferrari's Fernando Alonso could manage only fifth on the grid in front of his adoring home fans, just 0.001secs quicker than team-mate Felipe Massa.
Scot Paul di Resta was 10th as the top 10 was completed by Lotus's Romain Grosjean in seventh and Red Bull's Mark Webber in eighth.
Brazilian Massa was subsequently handed a three-place grid penalty for blocking Mark Webber during the Red Bull driver's timed lap in the second session, relegating the Ferrari driver to ninth on the grid.
"Congrats to Nico - really happy for the team," said Hamilton. "It's down to all the great work from the guys at the factory. But we've got to approach tomorrow with caution because it's going to be tough. I didn't have two option tyre sets, but I think Nico was quicker today."
But Mercedes have struggled for race pace this year and team principal Ross Brawn sounded doubtful when asked if they could win the grand prix, admitting others had been in better shape during the race-simulation runs in Friday practice.
F1 Spanish GP - Watch Nico Rosberg's pole lap for Mercedes
However, world champion Vettel said: "Mercedes were in a league of their own. We were surprised by the pace they had today. I am happy to sit in third right behind them because they were out of reach.
"I expect them to be strong in the race because they have been quick all year on this track and I expect the people behind to put some pressure on, Lotus and Ferrari. We will have to look after ourselves and our own tyres and then see what we can do."
The improved Toro Rossos of Daniel Ricciardo and Jean-Eric Vergne were 11th and 12th ahead of Force India's Adrian Sutil.
"The car didn't feel too bad in Q1," said Button of his poor qualifying. "I got held up on my lap and lost about 0.3secs in last corner from this morning but then in Q2 I just didn't have the grip on my last run. The tyre pressures came in massively high. We're just looking now to see if they were set properly."
On whether he was surprised by team-mate Sergio Perez's pace, he said: "I am considering where we are. He did a good job, obviously got everything right."
Williams continued to struggle - both cars failed to get past the first knock-out session despite a major upgrade package.
Eddie Jordan on McLaren and Williams's woes in 2013
Valtteri Bottas was 17th, 0.058secs ahead of team-mate Pastor Maldonado as the corner-entry instability that has plagued them all year seemed to still be a problem.
Deputy team principal Claire Williams said: "It's not why we come racing to not get drivers into Q2. The boys all work really hard, and we've got to improve. You never panic in these situations. The grid is so tight, we were only one tenth off getting into Q2 so I don't think it's time to panic."
Sauber's Esteban Gutierrez was handed the same punishment as Massa for impeding Kimi Raikkonen and will start the race in 19th position. The Mexican was previously given a five-place grid penalty for the last grand prix in Bahrain for his part in an incident with Adrian Sutil during the Chinese Grand Prix.
1. Nico Rosberg - Mercedes - 1:20.718
2. Lewis Hamilton - Mercedes - 1:20.972
3. Sebastian Vettel - Red Bull - 1:21.054
4. Kimi Raikkonen - Lotus - 1:21.177
5. Fernando Alonso - Ferrari - 1:21.218
6. Felipe Massa - Ferrari - 1:21.219 *handed three-place grid penalty for blocking. Starts ninth
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.