Hamilton covered the 2.722-mile Hungaroring course in 1 minute, 19.388 seconds.
Vettel had been in the top spot for much of Saturday with a 1:19.426 lap. Roman Grosjean of Lotus captured third with a 1:19.595.
Saturday's qualifying was held amid a European summer heat wave that sent temperatures on the track above 120 degrees.
All eyes were on tire performance and engine temperatures.
"The temperatures made it pretty tough," Hamilton said afterward. "I was really surprised when I came across the line and they said I got the pole. I was expecting Sebastian to get it, because he had shown some serious pace before."
Beyonce flaunts bikini body, Blue Ivy in vacation pics
Couple mistakenly served bag of cash at McDonald's drive-thru