The 27-year-old McLaren driver held off late pressure from Kimi Raikkonen's Lotus at the Hungaroring to secure a 19th career win - his third in Hungary - and he admitted afterwards that it had been a major test.
"It was a really enjoyable race - but it wasn't at all easy," he said.
"[It was] one of the toughest races I've ever driven. I'll savour it all the more for that."
Hamilton had pole position while Raikkonen started fifth and, suffering from a temperamental KERS issue, lost a place to Formula One championship leader Fernando Alonso.
But, as the pit stops shook out, the Finn rose to fourth on a long 26-lap stint on soft tyres before making a second stop for mediums on lap 46 - five after Hamilton - and preparing for a final hard charge.
Raikkonen exited the pits just as team-mate Romain Grosjean, who had started second, came screaming down the main straight, causing their engineers to sweat as they went through turn one side by side and Raikkonen forced Grosjean wide in order to steal the racing line and hunt Hamilton.
He was soon within a second of the Briton, but the McLaren driver was able to eke out faster third sectors, protecting himself down the main straight. There were no other opportunities for the Lotus to pass.
"I was under a lot of pressure throughout all 69 laps," said Hamilton, who has only won one other round this season.
"First, Romain and then Kimi were right behind me, all the way through, and I had to look after my tyres without letting my pace drop, which was pretty tricky at times.
"It isn't a static situation when a race goes like that. The feel of the car is changing all the time. You get different messages from the tyres with every lap. But they lasted - I managed to make them last.
"It was a case of managing the gap behind me, over the whole lap, every lap. In particular, I had to make sure that, every lap, I always had a big enough gap at the last corner, so that I wouldn't be overtaken in the DRS zone on the pit straight. And I managed to do that every time."
Grosjean held on to third ahead of world champion Sebastian Vettel, who made a third pit stop without losing a place and charged back to attack the Lotus on fresh soft tyres but to no avail.
Alonso calmly protected his points lead on a tough day for Ferrari, finishing fifth.
Hamilton, whose championship hopes were reignited after he retired at Hockenheim last time out, added: "This weekend shows it's all to play for still. After some bad races it's good to be back."
He moved one point ahead of Raikkonen to fourth in the championship standings with 117 points. Alonso stretched his lead over Mark Webber with 164 points to the Australian's 124. Vettel remained third with 122, closing the gap to his Red Bull team-mate.