Rosberg had been leading the race from Hamilton following a huge accident involving Kimi Raikkonen at the start that caused the race to be red flagged on the opening lap for the first time since 2000.
But with the race looking set for another grandstand finish between the Mercedes rivals on different strategies, Rosberg slowed and pulled off the circuit with a gearbox problem at just over half distance.
It allowed Hamilton to coast to the chequered flag for his second victory on home soil ahead of Valtteri Bottas (Williams) and Daniel Ricciardo (Red Bull) with Jenson Button (McLaren) an agonising fourth having never before been on the podium at his home grand prix.
"I don't want to see a team-mate fail, I want a one-two, but I really needed this result," said Hamilton on the podium in front of a cheering crowd.
There was drama from the outset. Raikkonen lost control of his car after running wide on the Wellington Straight on the opening lap, his Ferrari snapping sideways into the barrier before spinning back across the circuit when he rejoined the circuit.
Only lightning-fast reactions from Felipe Massa saved a much bigger accident, the Brazilian swerving to avoid a head-on collision with Raikkonen’s stricken Ferrari.
Sadly, the damage ended Massa’s 200th grand prix appearance. More important was the fact Raikkonen suffered only minor damage to his right ankle after limping away from his car following an impact measured at a massive 47g.
It took an hour to replace the damaged guardrail and when racing did resume, Rosberg stretched his lead at the front of the field with Hamilton quickly passing Kevin Magnussen and Jenson Button before setting about his team-mate.
Rosberg was the first to pit on lap 19 for medium tyres, Hamilton staying out longer before opting for the more durable hard compound. But with Hamilton lapping quicker and closing on his rival, Rosberg slowed and stopped with a gearbox problem and his first DNF of the season.
The one-stopping Bottas put in the drive of the day to finish second from 17th on the grid, Ricciardo finishing just 0.8 seconds ahead of Button at the finish.
A titanic duel between Sebastian Vettel and Fernando Alonso saw the German edge out his great Ferrari rival to take fourth, the two coming close to touching as Vettel squeezed past only four laps from the end.
Kevin Magnussen, Nico Hulkenberg, Daniil Kvyat and Jean-Eric Vergne rounded off the top 10.
"It [the gearbox problem] started on lap 20 and then it just got worse from there," said Rosberg. "There was nothing I could do or that they could suggest to save the gearbox.
"I was very much in control until then. That's why it's all the more disappointing."
- Sports & Recreation
- Motor Racing
- Kimi Raikkonen
- Jenson Button
- Daniel Ricciardo
- Valtteri Bottas