Hamilton’s championship rival Sebastian Vettel was expected to be the fastest in the dry, but, as ever, Hamilton turned on the style when the heavens opened.
The Englishman beat team-mate Valtteri Bottas by a quarter of a second to the top slot on the grid, with Ferrari’s Kimi Raikkonen third.
Vettel, 17 points behind Hamilton in the championship, finished only fourth, more than half a second down on his rival.
Dark clouds hovered over the Hungaroring before large claps of thunder ensured a downpour was imminent. Moments later, the rain arrived to ensure the first wet qualifying session since last September’s Italian Grand Prix.
On that day, Hamilton prevailed with a remarkable lap, and here the Briton was at it again to prove his credentials in the slippery conditions.
Vettel, who crashed out while in the lead at his home race in Germany last week, appeared cautious, and will now have his work cut out from fourth at a track where overtaking is difficult.
“We couldn’t have expected this because Ferrari have been quickest all weekend,” Hamilton, only fourth in final practice, said. “We were going to try and do our best to be as close to them as possible, but then the heavens opened and it was fair game.
“It is so tricky out there. Towards the end it was getting really wet and it is difficult to arrive at the corner and know how much grip you are going to have.”
Red Bull driver Daniel Ricciardo was the biggest victim of the changeable conditions.
The Australian failed to get in a good enough lap at the start of Q2, and as the rain intensified, he was unable to haul his car into the top ten shootout. He qualified only 12th.
Fernando Alonso, asked by his race engineer if he should stick to intermediate tyres or change to the full wet rubber, said: “Even if you put on a rocket ship we will [fail to improve on] 11th.”
Cash-strapped Force India, placed in administration on Friday following a court hearing, saw their off-track problems replicated on it.
Esteban Ocon and Sergio Perez, the Mexican driver who initiated the legal proceedings with his sponsors owed more than £3m, will start 18th and 19th of the 20 runners.