Two Palestinians armed with a meat cleaver and a gun killed four people in a Jerusalem synagogue before being shot dead by police.

Israeli Prime Minister Benjamin Netanyahu pledged to respond with a "heavy hand" and again accused Western-backed Palestinian President Mahmoud Abbas of inciting violence in Jerusalem.

Abbas issued a statement condemning the attack, the first time he has directly denounced violence after weeks of deepening unrest.

A worshipper who attended the morning service in the Kehillat Bnei Torah synagogue in an ultra-Orthodox neighborhood of West Jerusalem said about 25 people were praying when shooting broke out.

"I looked up and saw someone shooting people at point-blank range. Then someone came in with what looked like a butcher's knife and he went wild," the witness, Yosef Posternak, told Israel Radio.

The founder of Israel's Zaka emergency response service, which attended the scene, described it as like the slaughter of Jews in Europe during the Holocaust.

"The images I saw inside the synagogue reminded me of images from the Holocaust - Jews wrapped in talitot (prayer shawls) and tefilin (phylacteries) dying in pools of their own blood on the floor of the synagogue," Yehudi Meshi Zahav told Israel Radio.

Palestinian radio reports described the attackers as "martyrs" and the Islamist group Hamas praised the attack. Loudspeakers at mosques in Gaza called out congratulations. However, there was no direct claim of responsibility.

Palestinian media named the attackers as Ghassan and Udai Abu Jamal, cousins from the Jerusalem district of Jabal Mukaber, and said they were members of a small militant group.

Violence in Jerusalem, areas of Israel, and the Israeli-occupied Palestinian territories, has surged in the past month fuelled in part by a dispute over Jerusalem's holiest shrine, which has given rise to fears of a religious conflict.

Five Israelis and a foreign visitor have been deliberately run over or stabbed to death by Palestinians. About a dozen Palestinians have also been killed, including those accused of carrying out those attacks.

Residents trace the violence in Jerusalem to July, when a Palestinian teenager was burned to death by Jewish assailants, an alleged revenge attack for the abduction and killing of three Jewish teens by Palestinian militants in the occupied West Bank.

The summer war between Israel and Hamas militants in Gaza has also been a trigger for violence.