Vettel had comfortably led the race from pole position until a mistake in lap 52 saw the German lock up as he approached a hairpin turn, sending him into the gravel with no hope of recovery.
Meanwhile, it was an uphill battle for Hamilton after a hydraulic failure in qualifying saw him start at 14th on the grid.
But he picked off the competition one-by-one with ruthless precision, the field powerless to the Mercedes’ pace, rising 13 places to earn one of the most remarkable wins of his career.
The Brit’s teammate Valtteri Bottas came in behind for a Mercedes one-two, with his Finnish compatriot Kimi Raikkonen completing the podium.
The championship duel fires up
A reasonably pedestrian race roared into life after Vettel’s crash as teams scrambled to pit with rain on the horizon, before a thrilling wheel-to-wheel scrap between Bottas and Hamilton.
After a near-collision, the Mercedes garage called on Bottas to cool down his challenge, leaving the four-time world champion free to claim his fourth German Grand Prix title, level with legendary German driver Michael Schumacher.
It is the first time Hamilton has come from lower than sixth on the grid to win a Grand Prix, and it sets alight once more the fierce title duel with Vettel — as both chase a fifth championship.
Hamilton now boasts a 17-point advantage going into the Hungarian Grand Prix next week, before the championship takes a four-week summer break.
With 15 laps to go, Vettel looked to be strolling towards his first win at Hockenheim, stretching his lead in the overall standings after victory in Silverstone two weeks ago.
But the error in the turn could prove costly for the Ferrari driver, his voice trembling over the team radio as he rued a wasted opportunity.
Meanwhile it was emotion of a different kind on the Mercedes radio, as the team celebrated: “Miracles do happen, Lewis.”
“What an amazing job by you guys,” he replied. “Love conquers all.”
It was a rewarding result for the German team — the first time they had secured a one-two in the German Grand Prix — and in the same week as they confirmed the signing of both drivers for next season.
Hamilton signed a deal worth a reported $52 million per year until the end of 2020, while Bottas signed on for a third season with the team with the option of extending it to 2020.
But it was another race to forget for Red Bull driver Daniel Ricciardo, whose race was terminated in lap 29 after a power issue.
Having worked his way up to seventh from the back of a grid after a penalty from qualifying, the Australian driver lost power and was forced to stop the race.
It is his fourth retirement of the season, and despite wins in China and Monaco, hopes of mounting a title challenge seem to be ebbing away for the Red Bull driver.
Meanwhile his teammate Max Verstappen was hampered by a miscalculation with tyres that denied him the opportunity to challenge for the podium, finishing fourth.
And it was another frustrating day for Williams — celebrating their 700th race start in Formula 1 — as both Sergey Sirotkin and Lance Stroll retired once again, leaving the historic team bottom of the constructor standings with just four points from the first 11 races of the season.