Sebastian Vettel qualified second, just five hundredths behind, and Nico Rosberg third, making the top three a replica of the front of the grid in Australia two weeks ago.
With rain intensifying in the final moments of Q3 it looked as if Rosberg, Vettel and Alonso would all have chances to go quicker - but Rosberg and Alonso both failed to improve their times.
Vettel never even got a chance to improve, in the end: a terrible blunder of timing as he tried to wait for a clear track ahead meant that he crossed the start-finish line a few seconds too late, and missed the chance to squeeze in his final flying lap.
Hamilton relieved to take pole in 'incredible' rain
Such a crushingly amateur error is far from characteristic of Red Bull and Vettel, and the German was no doubt seething inside - particularly given how close he had been to Hamilton's time earlier on in the session.
Hamilton's pole was the 33rd of his career, equalling the British record that had been held by Jim Clark since 1964 - though Clark's poles were earned in just 73 races compared to Hamilton's 131.
Fernando Alonso was fourth fastest with Red Bull's Daniel Ricciardo fifth, while Jenson Button finished 10th in Q3 after a gamble on using intermediate tyres backfired on him.
Torrential rain left Sepang under several inches of water, delaying the start of the session for almost an hour.
But once things got under way, Hamilton was the fastest man on the circuit almost from start to finish as he showed yet again that the Mercedes seems to be the car to beat this season.
After a 50-minute delay, track conditions were still best-suited to full wet tyres in Q3 and Hamilton's first flying lap of 1m59.431s ended up benig good enough to secure pole position.
But his advantage was a small one, as he ended up just 55 thousandths of a second faster than Red Bull driver Vettel.
Rosberg showed disappointing pace on his first flier, ending up only fourth fastest, but with track conditions a little worse in the closing stages did enough to improve to third.
Alonso was the man he bumped down to fourth, although the Spaniard was fortunate to make Q3 after surviving a collision with Scuderia Toro Rosso driver Daniil Kvyat at Turn 9 during Q2.
The Spaniard suffered front-left suspension damage in the clash, which happened when he was struggling back to the pits on intermediate rubber while most were on full wets.
The Russian had closed rapidly on Alonso and dived to the inside of the slow left-hander, but Alonso turned in and Kvyat slid into him.
The incident will be investigated by stewards after the session.
Ricciardo was fifth fastest in the second Red Bull ahead of Kimi Raikkonen, who was the only driver other than Hamilton to head the times during Q3 - and that only for a few moments - with Force India driver Nico Hulkenberg seventh.
Behind him was Kevin Magnussen, who started Q3 on intermediates but pitted to change to wets, salvaging eighth place while team-mate Jenson Button stuck with the inferior tyre and ended up slowest in 10th.
Scuderia Toro Rosso driver Jean-Eric Vergne was the other driver to reach the top 10 shootout, ending up ninth.
Williams pairing Felipe Massa and Valtteri Bottas were the big-name casualties during Q2.
With everyone setting their times using wet Pirellis during the middle segment of the session, the Williams FW36 again struggled for traction in the low-grip conditions. And the pair ended up 13th and 14th respectively.
Vergne prevailed in a tense battle for the final Q3 slot, bumping Toro Rosso team-mate Kvyat from the position in the dying seconds of the session.
Sauber driver Esteban Gutierrez ended up 12th fastest ahead of the Williams pairing, with Lotus driver Romain Grosjean suffering a late spin and unable to do better than 16th after making Q2 for the first time this year.
Pastor Maldonado was unable to join his Lotus team-mate in the second phase of qualifying, ending up the fastest of those to miss the Q2 cut 0.385s slower than Vergne.
After the delayed start, every team apart from McLaren opted to send their drivers out on intermediate rubber in wet conditions, with the majority of the order dictated by pace during the first half of the session.
Sauber's Adrian Sutil, Marussia pairing Jules Bianchi and Max Chilton and the Caterhams of Kamui Kobayashi and Marcus Ericsson were the others to fall in Q1.
The session was brought to a premature close when Ericsson lost it on a wet kerb at the exit of Turn 3 after what the Swede described as a "silly mistake" and spun into the barrier, rebounding and coming to rest on the track.
Malaysian Grand Prix
Mercedes march on but Red Bull closing in
Malaysian Grand Prix
Magnussen disappointed with himself
Share this article