Vettel drove a flawless race from pole position to secure his fourth win of the season, his Ferrari teammate Kimi Raikkonen taking second place at the Hungaroring.
But it was far from straightforward for the German, whose car suffered from steering problems which saw his early advantage whittled away as Raikkonen kept station behind him.
Hamilton closed up on both Ferraris after an indifferent start but was unable to pass either on a circuit where it is notoriously difficult to overtake.
His Mercedes teammate Valtteri Bottas had allowed Hamilton through into third place so he could mount his challenge, but the pair swapped places on the last lap as they had agreed.
"I want to win the championship the right way," Hamilton told reporters.
"I don't know whether that will come back to bite me on the backside or not but I said at the beginning of the year, I want to win it the right way. I do think today was the right way to do things."
The move was applauded by Hamilton's Mercedes team, but his generosity cost the Briton three points and might prove crucial in a tight title race come the end of the season.
"It is important to stick by your word. Maybe someone will one day said, Budapest is when we lost the championship. Who knows," Mercedes team principal Toto Wolff said.
'Valtteri moved over because we asked him to move over and then Lewis moved over at the end. Fair play to both of them."
It was in marked contrast to the atmosphere in the Red Bull camp after a first-lap collision between its drivers Daniel Ricciardo and teenager Max Verstappen.
Both had gone past a sluggish Hamilton at the start, but on the second corner Verstappen clipped his teammate, ending the Australian's race.
Ricciardo, so consistent in recent grand prixs, could not mask his disappointment and frustration at a move which cost Verstappen a 10-second time penalty from the race stewards.
"I didn't really know what happened. It's just frustrating -- it was not even an overtaking move," he told BBC Radio Five.
"It was an emotional response.
"In that moment the team said sorry and they will speak to Max. Let's see if he acts his age or like a man about it," he added.
Despite the penalty, Verstappen finished fifth, his speed in the later stages of the 70-lap race seeing him close up on Bottas to threaten the agreement he had made with Hamilton.
Fernando Alonso finished sixth for McLaren, the team's best finish of the season and posted the fastest lap to cap his fine race.
Scotland's Paul di Resta, a surprise late replacement for the ailing Felipe Massa for Williams, was retired by the team late in the race because of a technical issue.
Vettel, claiming his 46th career win, leads the championship with 202 points, from Hamilton on 188 with Bottas on 169.
The F1 season now takes a four-week break ahead of the Belgian Grand Prix at Spa-Francorchamps.