* Briton wins second race in row, team mate Rosberg second
* Mexican Sergio Perez takes third place for Force India
The win - in Formula One's 900th grand prix - was the Briton's second in a row, the 24th of his career and also a second successive one-two for a team in a class of their own and with two drivers free to race each other from start to finish.
Mercedes have now won all three races so far in 2014.
"Nico drove fantastically well throughout the race. It was very, very hard to keep him behind me," smiled Hamilton, the 2008 world champion who last enjoyed back-to-back wins four years ago with McLaren.
"I was on the knife edge the whole time and a real relief when I got across the line," said the Briton, who won by 1.085 seconds and described the race as the hardest since his 2007 debut season.
Mexican Sergio Perez took third place - 22.9 seconds behind Rosberg - as Mercedes-powered Force India celebrated the second podium finish in their history.
Rosberg, winner of the season-opener in Australia, stayed top of the overall standings with 61 points to Hamilton's 50.
"I strongly dislike coming second to Lewis...but it was definitely the most exciting race I have ever done in my entire career," said the German, who had started on pole and whose disappointment was clear as he stood on the podium.
"I think today was a day for the sport."
Hamilton, whose tally of wins pulls him level with the late Argentine great Juan Manuel Fangio in the all-time lists, made the better start from second place on the grid and led into the first corner.
He was never able to shake off Rosberg though, with both jostling for the lead in a race that made a mockery of suggestions the new V6 turbo hybrid era had turned flat-out racers into fuel-saving taxi drivers.
"Warn him that was not on," Rosberg shouted over the radio after one attempt to get past Hamilton on the inside saw the German forced to run wide.
The Briton's task was made tougher when the safety car came out 15 laps from the end, after Pastor Maldonado T-boned the Sauber of Mexican Esteban Gutierrez at turn one and flipped it spectacularly through the air.
Venezuelan Maldonado was handed a stop/go penalty and a five place grid drop for the next race in China, while Gutierrez went to hospital for checks and was then released.
With Rosberg on the faster, soft tyres and ready to pounce as soon as racing resumed, it looked like Hamilton was sure to be passed but he held on for what amounted to a dash to the chequered flag.
"With 10 laps to race, can we just make sure we bring both cars home," technical head Paddy Lowe told both drivers over the radio and they did so but not without some heartstopping moments.
"I was just pushing to the limit, going for it and just making sure we don't crash," said Rosberg. "At no time were we at risk of taking both cars out. There was always the necessary margin...it was good racing."
Behind them, the rest of the field was fighting similar battles with team mates running in close two-by-two formation and scrapping for position.
Australian Daniel Ricciardo finished fourth, despite starting 13th and behind quadruple champion team mate Sebastian Vettel, who ended up sixth and had to let his young team mate through early on.
Nico Hulkenberg split the two Red Bulls in fifth place, and held up Ricciardo for long enough to ensure Perez's podium, with Williams team mates Felipe Massa and Valtteri Bottas seventh and eighth.
"One more lap and I couldn't manage to keep him back," Perez said of Ricciardo's charge behind him.
Ferrari's pairing of past champions, Spaniard Fernando Alonso and Finland's Kimi Raikkonen, rounded off the scoring positions in ninth and 10th on a dismal evening for the Italian team watched by their president Luca di Montezemolo.
McLaren, half owned by Bahrain state investment fund Mumtalakat, failed to get either of their cars to the finish of the country's 10th anniversary grand prix which was being held under floodlights for the first time.
Organisers said the race had drawn its biggest ever crowd, with 31,000 attending on Sunday.
They were untroubled by any protests in a country that has suffered sporadic unrest since an uprising led by its Shi'ite Muslim community in early 2011 demanded reforms and a bigger share of power in the Sunni-led government.
A handful of youths in the Shi'ite village of Eker burned tyres and threw rocks at police who responded by firing a few rounds of tear gas, Reuters witnesses said. The youths quickly dispersed after that.
Bahraini activists reported similar sporadic unrest in other areas with dozens of protesters marching inside villages and others throwing rocks at police who seemed to effectively block off the main entrances to the villages.
A small explosion was also heard in the centre of the capital Manama, although the cause was not immediately clear and there were no reports of casualties.