Hamilton was just 0.055 seconds quicker than the world champion, as team-mate Nico Rosberg narrowly beat Ferrari's Fernando Alonso for third.
Hamilton's pole was the 33rd of his career, equalling the great Jim Clark's record for a British driver.
Dramatic crash ends Ericsson's wet debutRed Bull's Daniel Ricciardo was fifth from Ferrari's Kimi Raikkonen.
Hamilton, Vettel and Alonso were all well clear of their team-mates in difficult conditions brought on by the tropical afternoon rain that so often affects the action at Sepang.
Hamilton headed Rosberg by 0.619secs, Vettel beat Ricciardo by 1.055secs and Raikkonen was 1.043secs adrift of Alonso.
"Today was incredible," Hamilton said. "How heavy was the rain? It was tricky out there for everyone because at the end it was almost impossible to see. I couldn't see where the track went, where the corners were, where to brake. I had to bail out of my final fast lap, so it was very close."
Rosberg knocked Alonso off third spot by 0.125secs at the very end of the session, when conditions were slightly worse than they had been at the start of the top 10 shoot-out.
Force India's Nico Hulkenberg excelled as usual in wet conditions with seventh, and Kevin Magnussen's impressive debut for McLaren continued with the Dane taking eighth place, with team-mate Jenson Button 10th.
Lewis Hamilton's pole was the 33rd of his career, equalling the great Jim Clark's record for a British driverButton took a gamble by choosing intermediate tyres for the final session, while everyone else was on the more heavily treaded full wet tyres in the soaking conditions.
The Englishman ended up 1.8secs slower than Magnussen, who had in any case seemed to have the edge throughout qualifying.
Button said he had no regrets about his decision, given that the best he could have hoped for would be to be two places further up the grid.
The front row, with Hamilton's Mercedes heading a Red Bull, matched that of the season-opening race in Australia two weeks ago, when qualifying also took place in the wet.
The difference was that this time the Red Bull was Vettel's. The world champion took full advantage of his car's excellent downforce to come close to beating the more powerful Mercedes.
"At the beginning of Q1, the heartbeat was rising very quickly when we realised there was an issue," said Vettel. "I came in, we restarted the car and that seemed to solve the problem. After that it was fine. It was good to go out and get another feel in the wet conditions.
"Q3 was not perfect. I would have loved to have a second go. My first attempt, I felt there was time to gain here and there. It was very close, too close. I should be on the good side for tomorrow but it depends on how good the start is. I'm happy with the result."
Lewis Hamilton: "I couldn't see where the track went, where the corners were, where to brake..."Toro Rosso's Jean-Eric Vergne was the other driver to make the top 10 in ninth place.
The stewards investigated a collision between Alonso and Vergne's team-mate Daniil Kvyat at the start of the second session, deciding to take no action after the incident was adjudged to be a misunderstanding.
Alonso took a wide line into Turn Nine and Kvyat went for the inside thinking there would be space, but they collided when they reached the apex.
The incident broke the front left track rod of Alonso's Ferrari but his mechanics were able to change it in time for him to make it safely through into the final top 10 shoot-out.
Kvyat just failed to make it through in 11th place, pipped by Vergne.
"The car felt very strange," said Alonso. "It was so light on the right corners and so heavy on the left corners that I could not even move with the two hands.
Hamilton 'proud' to match GB poles record"I don't blame him [Kvyat]. I think it was 50:50 probably, because I didn't see him. I was lucky to run again. I think he ran again also, so that was the best news."
The two Williams cars struggled in the wet as they had in Melbourne, with Felipe Massa taking 13th behind Sauber's Esteban Gutierrez, and team-mate Valtteri Bottas 15th behind the Force India of Sergio Perez.
Bottas was later demoted to 18th on the grid following a three-place penalty for impeding Ricciardo.
Mexican Perez, dropped by McLaren after just one season last year to make way for Magnussen, was 1.672secs slower than team-mate Hulkenberg in second qualifying.
Full qualifying resultsFull Malaysian Grand Prix coverage details
EmoticonEmoticon