Vettel, now 17 points behind the Briton after starting eight ahead, led from pole position until rain caused chaos in the closing laps, with the German sliding into the barriers in front of his home fans.
Hamilton, the reigning world champion, took the chequered flag for a record-equalling fourth German Grand Prix win, ahead of his Finnish team mate Valtteri Bottas and Ferrari’s Kimi Raikkonen.
“I’ve never had a race like this,” he said. “After racing for so many years you never know when you’re going to have a better race than your best race, but this is right there with them.”
It was the 66th win of his F1 career and minutes after the finish, the heavens opened with an array of thunder and lightning and a fierce downpour that would have stopped any race.
“Miracles do happen, mate,” Hamilton’s race engineer Pete Bonnington told him over the radio after a slow-burner that turned into one of the great comebacks of the Briton’s already stellar career.
Hamilton, who threw himself across the pitlane wall into the arms of his mechanics and also got a bear-hug from delighted Mercedes-Benz boss Dieter Zetsche, seemed about as stunned as anyone.
“The rain has come down and washed away all the negativity and its a glorious day,” Hamilton said, his voice wobbling. “It couldn’t be a better day.”
Beaten by Vettel in his home British Grand Prix at Silverstone two weeks ago, where he went from pole to the back of the field and up to second, he had turned the tables completely.
“Love conquers all,” he declared, a possible reference to a defiant message he had posted on Instagram after his car broke down in Saturday’s qualifying.
“It’s obviously very, very difficult from that position and highly unlikely but you’ve always got to believe,” added the four times champion, who said a long prayer before the race started.
“I really manifested my dream today.”
For Vettel, it was simply a nightmare – the chance to make big gains slipping through his hands in an instant. He now has 171 points to Hamilton’s 188.
He pummelled the steering wheel angrily after the car crumpled against the tyre wall, the lap 52 incident bringing out the safety car.
“I had it in my hands – small mistake, big disappointment,” said the German.
“It was just one of those moments. It was my mistake so apologies to the team. They did everything right.”
Hamilton, who was already up to fifth after 14 laps, had made his first set of soft tyres last for 42 laps but pitted before the rain came and went to ultrasofts.
Max Verstappen was fourth for Red Bull with Nico Hulkenberg fifth for Renault.
Romain Grosjean took sixth for Haas ahead of Mexican Sergio Perez and Frenchman Esteban Ocon for Force India in seventh and eighth.
Sweden’s Marcus Ericsson put Sauber in the points with ninth and New Zealander Brendon Hatley was 10th for Toro Rosso.