A lap of one minute and 30.076 seconds put the Mercedes man at the head of the grid, with neither Hamilton nor Vettel's team-mate Kimi Raikkonen able to improve on that time in their final laps.
"We had no idea what was going to happen today", said Hamilton.
"Somehow we turned it round, the vehicle felt great, it is a real surprise to be up here", said Hamilton.
Hamilton has spent much of the season embroiled in a close fight with Ferrari's Sebastian Vettel at the front of the pack, with his third straight win in Singapore catapulting him into a 28-point lead. "So I think it's more the driver here than the auto, to be honest".
Concurring Team boss Toto Wolff added: "A blistering lap, he put it all together, but we are left with some confusion because our auto wasn't good".
Ricciardo won the 2016 Sepang race and shared the podium with his teammate Verstappen and Mercedes' Nico Rosberg, who retired after winning last year's championship.
Vettel will start from last in the latest bitter blow for Ferrari.
"The auto seems to be unbalanced and that triggers an terrible lot of consequences and it was certainly one of the worst Fridays I can remember", the Austrian said.
Vettel's failure in the qualifying means that he will have to start Sunday's session from the very last of the grid.
"We had such a hard day yesterday; it was hard to know where we stood", said Hamilton.
"I'm happy [with my performance] but I'd rather have qualified in first place". Hamilton's teammate Valtteri Bottas finished the practice at fifth position and disqualified Vettel stood at the very last of the leaderboard.
He added: 'It's not ideal, not what you want when you think you've got it in you.
Typically, not setting a time during qualifying would bar a driver from starting a race, but the FIA has granted Vettel an exception, due to his times set in practice. At least Raikkonen saved face, finishing just 0.045 seconds behind Hamilton's time.
The Finn, who recorded his maiden grand prix win at Malaysia back in 2003, thought he might have pipped Hamilton to pole but was edged out by just four-hundredths of a second. They fixed it quickly and it's a shame I couldn't get out - but we go tomorrow'.
"I had a couple of hard race weeks for myself in the last few weeks but really hoping to lift my performance this weekend", said the 28-year-old driver from Finland. "It just goes to show you never know what can happen".
"We haven't seen Sebastian obviously and Kimi was on a very good lap but made a mistake and at the end, the stopwatch is what counts".
The second Mercedes of Valtteri Bottas was fifth, with Esteban Ocon completing the top six in his Force India.