"I'm over the moon, that was a really difficult race," said the winner, who had to wrestle with a skewed steering wheel on a sweltering afternoon at the Hungaroring and had no room for error.
Hamilton finished fourth after slowing down on the last lap and allowing Finnish team mate Valtteri Bottas to go past, despite the loss of vital points to the Briton's championship challenge. Bottas had let Hamilton through on the 45th of the 70 laps, on the assurance that his team mate would hand back the place if he could not overtake the Ferraris, and the triple champion duly kept his word.
"Really thanks to Lewis for keeping the promise in the end and letting me by," said Bottas. "I don't think every team mate would have swapped back."
Hamilton, whose radio was malfunctioning for some of the race and would have had more of a chance had he got past Bottas earlier, said he had done what he had to do.
"It's tough in the championship but I'm a man of my word," he said. "I did say that if I can't overtake them I would let him back through."
On a circuit where overtaking is notoriously hard, the top five all finished in their starting order with Max Verstappen fifth for Red Bull. The Dutch teenager was handed a 10-second stop and go penalty for colliding with his Australian team mate Daniel Ricciardo on the opening lap. The impact ended Ricciardo's race, with the car stranded on the track and fluid leaking from the broken radiator, and brought out the safety car.
"It's not on. It was amateur to say the least. It's not like he was trying to pass – there was no room to pass," said an angry Ricciardo.
"I don't think he likes it when a team mate gets in front. You've got the whole race to try and repair the mistake but the pass was never on. It wasn't even a pass, it was a very poor mistake."
Fernando Alonso, who celebrated his 36th birthday on Saturday, gave struggling McLaren their best finish of the season so far by taking sixth place and also setting the fastest lap of the race. Belgian team mate Stoffel Vandoorne was 10th in a double points finish for the former champions, who moved off the bottom of the table and ahead of Sauber. Spaniard Carlos Sainz was seventh for Toro Rosso with Mexican Sergio Perez eighth and Force India team mate Esteban Ocon ninth. Britain's Paul di Resta, replacing unwell Brazilian Felipe Massa at Williams, retired.
The last Ferrari driver to win from pole position in Hungary was Vettel's compatriot Michael Schumacher, who was dominant in 2004 and went on to win his seventh and last championship that season. Hungary was the last race before the August break, with nine of the 21 rounds remaining. (Reporting by Alan Baldwin, editing by Pritha Sarkar)