Rosberg's time of 1 minute, 33.185 seconds at the Bahrain International Circuit was a quarter of a second faster than Hamilton, who had to abandon his final flying lap after running wide at the first corner.
It was Mercedes' third straight pole to start the Formula One season but the first for Rosberg, who equaled his father Keke with five career poles. Rosberg leads the championship on 43 points, 18 ahead of Hamilton.
"It has just worked well through the weekend, finding my way, making progress and getting through some issues," Rosberg said. "I have good memories of this track, winning the GP2 championship and starting my first race in F1. I enjoy coming here and again today it's suited me."
Rosberg and Hamilton have a win each from the opening two races of the season and Mercedes also dominated the three practice sessions leading into qualifying, both in day and night conditions, with Sunday's race to be held at night for the first time.
The only surprise was Rosberg taking pole ahead of Hamilton, who usually thrives in the one-lap format.
"I locked up in the last lap but generally I am happy for the team," Hamilton said. "Nico did a great job and naturally I'm happy my teammate is there and not someone else."
Defending four-time F1 champion Sebastian Vettel did not even make the final session of qualifying and will start from 10th on the grid — promoted one spot as his Red Bull teammate Daniel Ricciardo, who qualified third, gets a 10-place grid penalty from the previous race in Malaysia.
Vettel paid the price for a session-ending spin in pre-qualifying practice which prevented him from getting valuable data on how to set up the car on the soft-tire, low-fuel setting. He also complained of a downshifting problem.
"The final run for some reason was a bit more difficult, the rears were locking up," Vettel said. "We had been playing around with it for quite a while, we are still not where we want to be but I don't want to blame it on that. There was a little bit more in the car which I couldn't get to, so I am not happy with today."
Williams driver Valtteri Bottas and Force India's Sergio Perez qualified fourth and fifth respectively and, with the one-place promotion, both equaled their best career starting positions.
Ferrari's Kimi Raikkonen qualified sixth, four places ahead of Fernando Alonso, to take the qualifying honors over his teammate for the first time this season in what is expected to a year-long fight between the two former world champions.
Alonso said the car was down on power in the final part of qualifying, though he felt the team's starting grid positions of fifth and ninth were "more or less what we expected to be honest."
"Q2 we were down a little bit and Q3 we lost more," Alonso said. "Still, we didn't miss out on the possibility of pole position because we are not in that kind of position. It's just a couple of places that hopefully tomorrow we can recover."
McLaren's Jenson Button, contesting his 250th grand prix, qualified in seventh and his teammate Kevin Magnussen was ninth, separated by Felipe Massa of Williams.
Aside from Vettel's early elimination, the main surprise of Q2 was Force India's Nico Hulkenberg qualifying in 12th, having been fastest of all drivers in Q1 and showing strong pace during the practice sessions.
Sauber's Adrian Sutil was hit with a five-place grid penalty for impeding Lotus' Romain Grosjean in the first session of qualifying, sending him to the very back of the grid.