Armed militants have killed 20 people, most of them foreigners, after taking them hostage in a Bangladesh cafe, with many of the victims hacked to death before police stormed the building rescuing 13 others, officials say.

Key points: Gunmen stormed the restaurant Friday night, taking hostages

Gunmen stormed the restaurant Friday night, taking hostages Islamic State has claimed responsibility for the attack

Islamic State has claimed responsibility for the attack PM pleads with extremists to stop killing in name of Islam

Six gunmen were killed during the police operation and one was captured, Prime Minister Sheikh Hasina said in a TV broadcast.

"Most of [the hostages] were killed mercilessly by sharp weapons last night," before the siege began, Army Brigadier General Naim Asraf Chowdhury said.

The army concluded an operation to clear the cafe on Saturday after a 12-hour siege that began when gunmen stormed the restaurant on Friday, which was popular with foreigners.

The Bangladesh army said that most of the slain civilians were either Italian or Japanese, while officials have confirmed an Indian teenager and a US citizen to have been among the victims.

Police outside the scene of the Dhaka cafe massacre ( Facebook: Shaheen Mollah )

Italy's Foreign Minister confirmed that nine Italians had been killed, while one other Italian national was still missing.

Japan Chief Cabinet Secretary Yoshihide Suga later confirmed that seven Japanese citizens were killed in the attack.

The 13 hostages that were rescued included one Japanese and two Sri Lankans, Brigadier General Chowdhury said.

One Japanese man was among those rescued and taken to a Dhaka hospital with a gunshot wound, a Japanese government spokesman said.

In a late night televised address in which she declared two days of mourning, Bangladesh's Prime Minister Sheikh Hasina pleaded with Islamist extremists to stop killing in the name of religion.

"Islam is a religion of peace. Stop killing in the name of the religion," she said.

"Please stop tarnishing our noble religion ... I implore you to come back to the rightful path and uphold the pride of Islam."

The premier called on people to set up "anti-terrorism committees" in districts and sub-districts across the mainly Muslim but officially secular country.

Sorry, this video has expired Scenes outside the Holey Artisan Bakery after 20 hostages taken by gunmen.

Wave of murders by suspected Islamist militants

Police said the gunmen burst into the restaurant shouting "Allahu Akbar" (God is Greater) as people were having dinner about 9:20pm and set off explosives.

The Holey Artisan Bakery was located about 800m from the Australian High Commission. ( Google Maps )

Some diners managed to escape including an Argentine chef and a Bangladeshi man who took refuge in an adjacent building.

The attack, claimed by Islamic State, marks a major escalation in a campaign by Islamic militants targeting individuals advocating a secular or liberal approach in mostly Muslim Bangladesh.

Bangladesh has been reeling from a wave of murders of religious minorities and secular activists by suspected Islamist militants.

Earlier on Friday, a Hindu temple worker was hacked to death in western Bangladesh.

Police also shot dead two Islamist students suspected in last month's murder of an Hindu priest and arrested a top Islamist militant who masterminded an attack on a Hindu lecturer last month.

Map The Holey Artisan Bakery, the scene of the shooting, is located in a popular area of Dhaka in Bangladesh

AFP/Reuters