Hamilton, who also won last weekend in Malaysia, finished 1.085sec ahead of Rosberg in another triumph for the Mercedes team who have won all three races this season.
Sergio Perez in a Force India was third, a huge 24.067sec off the winner's time, to give his team just their second podium finish.
Red Bull's Daniel Ricciardo, who had started in 13th place, was fourth, followed by Nico Hulkenberg in the second Force India and world champion Sebastian Vettel in the second Red Bull completing the top six.
The British driver had been cruising to victory in the 900th ever grand prix with a lead of more than nine seconds when the safety car was called out on lap 42 of the 57-lap floodlit race.
Also Read
Rosberg, who had been on pole, then briefly slipped past the Briton but Hamilton reasserted his authority under braking despite his medium tyres lacking the grip of the German's softer options.
On the final lap, Hamilton consolidated to take his first win in Bahrain after a memorable close-quarters battle.
"It was really exciting, Nico drove fantastically well, it was so fair but it was so hard to keep him behind me, I was on a real knife edge at the end but just managed to take it."
- Rosberg despondent -
======================
Despite Rosberg's second place, the German was despondent he could not retake the lead in the closing stages.
"It's very disappointing. I hope to get it right next time," said Rosberg, who hit back at critics who claim the dominance of Mercedes was bad for the sport.