The German was never headed after taking the lead from pole and had a big cushion over Ferrari's Sebastian Vettel in second place. Sergio Perez of Mexico took the final podium spot for Force India.
Hamilton, who endured a nightmare qualifying session Saturday to place 10th on the grid,
had to settle for fifth place after suffering recurring technical problems during the 51-lap race.
Both Hamilton and Ferrari's Kimi Raikkonen in fourth fell foul of the new 2016 rules which restrict the information that can be given to drivers over the team radio.
Hamilton, who might have challenged for a podium spot, was told by his engineers that the settings on his car were wrong, but grew frustrated as they were unable to give him more information.
"This is ridiculous guys," he said as he examined the buttons on his steering wheel at one point threatening to push them all.
"We wouldn't advise you do that," came the reply back.
After the race, Hamilton bemoaned these "silly rules" but said his team had work to do to sort out the technical glitches that have undermined his challenge.
Finn Raikkonen was in a similar predicament as he ceded third place to the late charging Perez, who, it is rumored in the paddock, could replace him at Ferrari next season.
It was the 19th career victory for Rosberg and fifth of the season as he battles for his first F1 title.
He had come under pressure after reigning two-time champion Hamilton won the previous two rounds in Monaco and Montreal, but has reopened a 24-point gap in the standings.
"The weekend went perfectly. Thanks to Baku -- the event has been awesome," he said on the podium.
It was the first time that the new 3.7 km street circuit in the capital of Azerbaijan had hosted a race, being awarded the European Grand Prix.
Behind the front runners, Valtteri Bottas took sixth for Williams ahead of the disappointing Red Bull pair Daniel Ricciardo and Max Verstappen.
Nico Hulkenberg in the second Force India and Brazil's Felipe Massa in the second Williams completed the points scoring positions.