Hamilton had been struggling for pace all weekend but was able to light up the timesheet at the right moment and will start first ahead of Vettel's team-mate Kimi Raikkonen and the Red Bull of Max Verstappen.
Vettel, who had been one of the quickest drivers all through practice, failed to set a time after being beset by engine problems, causing a huge blow to his championship hopes. He can ill afford another blip in Malaysia, where the intense heat and stifling humidity make it one of Formula One's toughest races.
He edged Ferrari's Kimi Raikkonen by 0.045sec.
A record four-time victor in Malaysia, Vettel desperately needs a fifth victory after his title hopes were dealt a severe blow at the last race in Singapore, where the German crashed out on the opening lap to clear the way for Hamilton to win. "It's great to see them performing so well and we want them to be closer". I had a really good time.
Hamilton, who retired from a dominant lead with a blown engine in Malaysia previous year which eventually cost him the title, capitalised on Vettel's misfortune to take victory in Singapore.
The Formula 1 Series returns to action this weekend with the running of the Malaysian Grand Prix.
Hamilton added: "I went into the last race thinking I would lose a lot of points to Sebastian, so to come out the other way around it was a real surprise".
Centuries of friction between Catalonia and Spain
Hundreds of police reinforcements, including the national Civil Guard, have been brought into Barcelona and other cities. If Catalonia favours a split, the pressure on Madrid to allow an official vote will grow, according to analysts.
Ghana 4 - 1 Nigeria...Stars Win WAFU 2017 Tournament
Nigerian football team has lost in a WAFU Cup to Ghana in a match the ended 4-1, played at the Cape Coast Stadium in Ghana yesterday.
Japan's Abe says he will call snap election for parliament
His three-year term as party leader ends next September, and he will have to fend off any challengers from within the LDP to remain prime minister.
Vettel had surprisingly held the upper hand over Hamilton throughout practice but suffered an issue in the final session and required a new engine.
"It's part of motor racing", Vettel told Sky Sports.
"We need to see now what the problem is but we managed to do the change in time".
"The damage is very big on the vehicle, we do not know exactly how much damage there is as it had just come back when I came here (to press conference)". "I have worked hard to prepare for this and to get to F1".
"For sure it's not what you want, especially on a day when you feel you've got it in you and in the vehicle".
"But I can feel for Ferrari and I can feel for Sebastian because I know it's a hard situation".
"If the safety auto comes out at a time that suits you, it might bring you back and then you never know what is possible". Renault's Nico Hulkenberg finished seventh ahead of Force India's Sergio Perez, while the second McLaren driven by Fernando Alonso rounded up the top ten positions.