While Vettel celebrated his second win of the season, only days after the funeral of the team’s French former test driver Bianchi, Mercedes’ double world champion Hamilton finished sixth after starting from pole.
That setback was still enough for the Briton to increase his championship lead to 21 points over team mate Nico Rosberg, who collided with Australian Daniel Ricciardo while fighting to defend second place and ended up eighth.
Russian Daniil Kvyat took second instead for Red Bull — his first F1 podium appearance — with team mate Ricciardo following home in third after banging into both Mercedes on a battling afternoon.
Dutch 17-year-old Max Verstappen was fourth for Toro Rosso.
Vettel dedicated his win to Bianchi, the Marussia driver who died in hospital nine months after suffering severe head injuries at the Japanese Grand Prix, once he had taken the chequered flag.
Speaking in French for the watching family, he added in English: “We know sooner or later Jules would have been a part of this team.”
The win was Vettel’s 41st, putting him level with the late triple champion Ayrton Senna on the all-time lists, and first in Hungary.
The result ended a record run for Mercedes and their two drivers, who had won eight of the previous nine races and started all on pole.
Hamilton’s run of 16 podiums in a row, and 18 successive races with at least one lap led, came to an abrupt and unexpected end.
The double world champion went from runaway favourite to scrapping for a point after being handed a drive-through penalty for causing a collision with Ricciardo.
“Today was weird. Do I deserve any points? I didn’t give up and drove as hard as I could,” said Hamilton. “To come away from one of the worst performances I’ve put in in a long, long time… it shows we are human.
“I was all over the place. I don’t have any words to explain what happened today. It was a really bad performance from myself.
“I pushed and never gave up but when I had two different choices I chose the wrong one every time.”
Rosberg, who had looked poised to win and take the championship lead at one point, could only rue what might have been as Mercedes’s hopes of getting both drivers on the podium for a record 10th race in a row evaporated.
However, even eighth was a bonus after the German struggled to guide his stricken car back to the pits with a flailing tyre after his collision.
The race took an unexpected and sensational twist right from the off as Vettel made a stunning start to seize the lead.
With Ferrari team mate Kimi Raikkonen following through to slot into second place, Hamilton and Rosberg were caught napping.
What might have been Ferrari’s first one-two finish since Germany in 2010 unravelled after 40 of the 69 laps when Raikkonen reported a loss of power and then retired.
Vettel looked comfortable until the safety car again ripped up the script, deployed after Nico Hulkenberg’s Force India shed a front wing and left an explosion of debris across the track before slamming into the tyre barrier.
That left the leaders tightly bunched again but Hamilton, by then up to fourth, collided with Ricciardo after the re-start and dropped down to 13th. After the drive-through penalty, he was 15th.
On a day of surprises, McLaren’s miserable season suddenly looked brighter with Fernando Alonso fifth and Jenson Button ninth — their first double points finish of the year and new Honda partnership.
France’s Romain Grosjean was seventh for Lotus while Sweden’s Marcus Ericsson took the final point in 10th for Sauber.