The 29-year-old German produced a fastest lap in one minute and 24.681 seconds in the final Q3 segment of the action to outpace the defending world champion by three-tenths of a second on a hot afternoon at the Circuit de Catalunya, where Hamilton won from pole last year.
His lap was quicker than Hamilton's 2014 pole time and ended the 30-year-old Briton's run of four straight poles this year. Rosberg now has to convert that advantage into a first win since last year's Brazilian Grand Prix to reduce Hamilton's 27-point lead in the title race.
"Strategy is important," he said. "It's a big advantage to have a new set of used tyres for the race. Overtaking is more difficult around here, so starting in front is a big advantage."
Eight of the last 10 Spanish races at Montmelo have been won from pole.
Also Read
"Of course I needed it sooner rather than later," added Rosberg. "It is one step in the right direction to winning the race. It was a good day in the office."
"I did not have the pace today and Nico did a great job," he said. "I didn't have the balance where I liked it, but tomorrow there's still a lot to play for. I didn't think I was on the back foot, I just didn't have pace the and I didn't do a great job."
Four-time champion Sebastian Vettel was third-fastest for Ferrari ahead of Finn Valtteri Bottas of Williams, Spaniard Carlos Sainz and his Toro Rosso team-mate, Dutch teenager Max Verstappen.
It was the first time that Toro Rosso had qualified a car in the top 10 at the Spanish event.