Twenty hostages have been killed during a siege in a cafe in the Bangladesh capital Dhaka.

At least six militants were also killed and 13 hostages rescued after Bangladeshi security forces stormed the restaurant popular with foreigners to end a 10-hour stand-off.

Gunmen stormed the Holey Artisan Bakery in Dhaka's Gulshan area, a diplomatic zone, on Friday night.

A Japanese government spokesman said that a Japanese hostage was rescued with a gunshot wound but seven others are unaccounted for. Deputy chief cabinet secretary Koichi Hagiuda said that the eight were together at the restaurant during the attack.

Bangladesh military spokesman Nayeem Ashfaq Chowdhury said two police officers were also killed when the attackers stormed the restaurant and opened fire.

The paramilitary troops who mounted the rescue operation recovered explosives from the scene.

The Islamic State group claimed responsibility for the attack, according to the SITE Intelligence Group.

Prime minister Sheikh Hasina condemned the attack and said security officials arrested one of the militants.

"Because of the effort of the joint force, the terrorists could not flee," Ms Hasina said in a nationally televised speech, vowing to fight militant attacks in the country.

"Anyone who believes in religion cannot do such act," she said. "They do not have any religion, their only religion is terrorism."

It was reported that two Sri Lankans were also rescued along with an Argentinian and two Bangladeshis.

The audacious attack came during Ramadan, when people in the mostly Muslim country fast during the day and eat after dark.

On Friday evening, many people headed to the popular bakery and restaurant that serves Spanish food and is patronised by residents of Gulshan, an affluent neighbourhood where most of the foreign embassies are located. The restaurant overlooks a lake and on pleasant evenings, diners often chose to eat outdoors.

Kitchen worker Sumon Reza, who escaped, said the attackers chanted "Allahu Akbar" (God is Great) as they attacked at around 9.20pm on Friday, initially opening fire with blanks.

Rezaul Karim, the father of a Bangladeshi businessman who was rescued along with his family, said the attackers did not harm any hostage who could recite verses from the Koran.

Mr Karim said his son, Hasnat, had gone to the restaurant along with his wife and two children to celebrate the birthday of his elder daughter when the attack happened. "He told me, 'Please save us, please.' And he hung up," he said.

Mr Karim said his son told him that the attackers "did not hit people who could recite verses from the Koran. The others were tortured."

"The gunmen asked everyone inside to recite from the Koran. Those who recited were spared. The gunmen even gave them meals last night," Mr Karim said.

Police said the two officers died in hospital after being wounded in the initial gunfire. Ten of 26 people who were wounded when the militants opened fire were in a critical condition, and six were on life support, according to hospital staff. The injuries ranged from broken bones to gunshot wounds.

The attack marks an escalation in the militant violence that has hit the traditionally moderate Muslim-majority nation with increasing frequency in recent months. Most attacks have been by machete-wielding men singling out individual activists, foreigners and religious minorities.

The government did not directly comment on the IS claim but has denied that the extremist group based in Syria and Iraq has a presence in Bangladesh, instead blaming the recent violence on its political enemies.

In Washington, a White House official said President Barack Obama was briefed on the attack by his chief counter-terrorism adviser Lisa Monaco.

Italian premier Matteo Renzi said that Italians were among the victims of the Dhaka attack but he would not give details until families are notified.

Mr Renzi said "we followed the events" in Dhaka "all night hoping for a different outcome," and added that a government plane was flying to the city.

Italian news reports suggest about 10 or 11 Italians were inside the cafe when the attack began.

India's foreign minister said an Indian girl was among the 20 hostages killed.

Sushma Swaraj said she is "extremely pained to share that the terrorists have killed Tarushi, an Indian girl who was taken hostage in the terror attack in Dhaka".