The 2008 Formula One world champion, a triple winner in Hungary with McLaren, lapped the circuit with a best time of one minute 19.388 seconds to deny Red Bull's Sebastian Vettel the top slot.
"Are we on pole?," the Briton shouted over the radio on his slowing down lap at the Hungaroring. "Yeah, we're as surprised as you," came the reply.
Triple world champion Vettel, who leads Ferrari's Fernando Alonso in the standings by 34 points after nine of 19 races, could manage only 1:19.426 with the track temperature hitting 50 degrees earlier in the session. He starts second.
Hamilton had never before in his stellar career taken three successive poles and his fourth of the season took his overall tally to 30 - one more than the late Argentine five-times champion Juan Manuel Fangio.
" So far looking after the tyres in these conditions is going to be, as always, trouble," said Hamilton. "These guys are going to be ridiculously fast so trying to be keep ahead of them or hold on to them is going to be the challenge tomorrow."
Frenchman Romain Grosjean qualified third for Lotus with Hamilton's German team mate Nico Rosberg fourth. Alonso, who has not started on pole for more than a year and turns 32 on Monday, will start fifth.
"At the end of the day I was pretty happy with my lap, but it was just not quick enough," said Vettel who dominated Friday practice but has never won in Hungary.
"Obviously Mercedes have a very strong pace in qualifying. I think Lewis did an exceptional job today, if you look also the gap to Nico (Rosberg) so you have to be fair and respect that so I'm not arguing with that. Surely I would have loved to have been a little bit faster and to have been on pole. But still, I think it puts us in a great place for tomorrow."
The race will be the first using the new Pirelli tyres, which have been changed to marry the current compounds with last year's structure after a spate of blowouts in Britain last month threw the sport into crisis.
Mercedes were the only team who did not try out the new tyres in Silverstone last week, as a punishment for a 'secret' test with Pirelli in Spain in May, but their absence did not appear to hurt them.
Compatriot Mark Webber, the man Ricciardo hopes to replace at Red Bull next year, starts 10th after suffering KERS problems from the second phase of qualifying.
McLaren's hopes of an improved showing at a circuit that has been good to them in the past, with six wins in eight years, faded with Mexican Sergio Perez qualifying ninth and Britain's Jenson Button 13th.