Five Israelis were killed in Jerusalem's bloodiest attack for years when two Palestinians armed with a gun and meat cleavers ran amok among worshippers in a Jerusalem synagogue on Tuesday.

It was a rare assault on a place of worship and sent shockwaves through the country, raising fears that the Israel-Palestinian conflict was taking on a more dangerous religious dimension.

Four of the victims were Israelis with dual nationality -- three US citizens and a Briton, police said. Israel's leading ultra-Orthodox website said they were all rabbis.

A policeman, Zidan Saief, 30, died later of his wounds.

Israeli Prime Minister Benjamin Netanyahu vowed a harsh response to the bloodshed, and pledged to demolish the homes of the perpetrators in line with a policy announced earlier this month.

"We are at the height of an ongoing terror attack focused on Jerusalem," he said, describing it as "a battle" over the fate of the Holy City.

"This evening, I ordered the destruction of the homes of the Palestinians who carried out this massacre and to speed up the demolition of those who carried out previous attacks," he said, referring to the homes of those behind four earlier attacks in the city.

Abbas condemned the killings, but Hamas welcomed the attack, with masked Palestinian militants in southern Gaza holding up knives and axes next to posters of the attackers while others handed out cakes in celebration, an AFP correspondent said.

US President Barack Obama called for calm after what he described as a "horrific attack", urging Israelis and Palestinians to work together to "lower tensions, reject violence and seek a path forward towards peace".

UN Secretary General Ban Ki-moon condemned the attack and lamented a worsening of the wider situation.

"The steadily worsening situation on the ground only reinforces the imperative for leaders on both sides to make the difficult decisions that will promote stability and ensure long-term security for both Israelis and Palestinians," he said.

The bloodshed took place as months of unrest gripped Jerusalem's annexed Arab eastern sector, resulting in a string of deadly attacks by lone Palestinians.

But none was as serious as Tuesday's killings at the synagogue in an ultra-Orthodox neighbourhood on the city's western outskirts as worshippers gathered for morning prayers.

The attack began shortly before 7:00 am (0500 GMT) when the assailants burst in, waving meat cleavers and a gun at the synagogue in a Jewish seminary in Har Nof.

Four people were killed immediately and at least eight wounded, with eyewitnesses saying several people had limbs hacked off.

The policeman died later.

The attackers, who were killed during a gunbattle with police, were identified as Uday and Ghassan Abu Jamal, cousins from Jabal Mukaber in east Jerusalem. Both were in their 20s.

Analysts warned a harsh Israeli response could potentially escalate a situation already fraught with tension.

"This event has the potential of being a game changer," said Kobi Michael, senior researcher at the Institute for National Security Studies.


Death to terrorists

Witnesses spoke of a bloodbath.

"Two people came out with their faces half missing, looking like they'd been attacked with knives," resident Sarah Abrahams told AFP as hundreds of ultra-Orthodox Jews pressed up against the police tape, a few chanting "Death to terrorists."

Emergency worker Moti Bukchi said the scene was "harrowing".

"Inside the synagogue some were wounded by gunshots, others had chopped off limbs caused by a meat cleaver," he told AFP.

Jerusalem Mayor Nir Barkat also expressed shock at the savagery of the attack which took place just over a mile (1.5 kilometres) from the Yad Vashem Holocaust museum.

"To slaughter innocent people while they pray... it's insane," he said.

Har Nof is also close to the former Palestinian village of Deir Yassin where Jewish militias massacred more than 100 villagers in 1948.

The last such attack was in March 2008 when a Palestinian gunman killed eight students at Mercaz HaRav yeshiva just two kilometres away before being shot dead.

In Jabal Mukaber, police rounded up the perpetrators' family members, sparking clashes with stone-throwing youths, relatives said. Police confirmed arresting nine people.


Netanyahu urges calm

Arab east Jerusalem has been a tinderbox since early July when Jewish extremists killed a 16-year-old Palestinian in revenge for the murder of three Jewish teenagers, sparking a wave of violence which has shown no sign of letting up.

Defence Minister Moshe Yaalon vowed to hunt down those who sent the perpetrators "both inside and outside Israel's borders".

But Netanyahu called for the public to "respect the law" and warned Israelis against revenge attacks.

"It is forbidden for anyone to take the law into their own hands, even if tempers are high and even if you're burning with anger," he said.

Israel police commissioner Yohanan Danino pledged to beef up security around both synagogues and mosques, and said police would be on alert to prevent further violence and revenge attacks, including so-called "price tag" hate crime by Jewish extremists.

US Secretary of State John Kerry condemned the attack as an "act of pure terror and senseless brutality," and called on the Palestinian leadership to denounce it.

But Hamas called for further attacks, saying it was a "response" to the death Sunday of an east Jerusalem bus driver found hanged inside his vehicle.

Israeli pathologists ruled out foul play but a Palestinian doctor who attended the autopsy suggested he had been murdered.