The Monegasque also praised his team after his car had gearbox problems in the first practice session on Friday.
"The team has done an amazing job and I'm extremely happy to be on pole. We had a very tough Friday, yesterday was not my day, but I worked hard in the car and it paid off today," he said.
Hamilton, a four-time winner in Singapore, admitted: "I don't know where Ferrari picked up their pace because this is not known to be one of their tracks, but they did a great job.
"I needed something special at the end, so I gave it absolutely everything I had. It was very, very close. I'm sure I nearly hit the wall a couple of times but it was as much as I could get out of the car.
"I'm really, really happy to be on the front row in the mix with them and try and divide them tomorrow," he said in the direction of Ferrari.
Hamilton leads the championship 63 points ahead of team-mate Valtteri Bottas after 14 of 21 season races as he is firmly moving towards a sixth world title.
"Maybe I peaked a bit early, we had a tiny wobble and there was no point in finishing that lap," the German four-time race winner said.
"It puts us in a good position tomorrow. It should be a good race, lets see what the tyres are going to do, if we can push for the two hours or will we have to manage them."
Red Bull's Max Verstappen, who had impressed in Friday practice, qualified fourth ahead of Bottas. Racing Point's Sergio Perez was 11th but loses five spots over a gearbox change following a crash in morning practice.