Seven militants who killed 20 people at a Dhaka restaurant were Bangladeshis and authorities had earlier tried to arrest five of them, said officials who denied claims by Islamic State of responsibility for the attack.

The gunmen stormed the upmarket restaurant in the diplomatic zone late on Friday and killed their mostly non-Muslim hostages, including nine Italians, seven Japanese and an American.

Claiming responsibility, Islamic State warned citizens of "crusader countries” in a statement that they would not be safe "as long as their aircraft are killing Muslims".

It also posted pictures of five grinning fighters in front of a black flag who it said were involved in the attack, according to the SITE monitoring website.

But Bangladesh Home Minister Asaduzzaman Khan told Reuters late on Saturday that neither Islamic State nor al Qaeda were involved. He reiterated the government statement that home-grown militants were responsible for a spate of killings in the country over the past 18 months, including the latest one.

“This was done by JMB,” Khan said, referring to Jamaat-ul-Mujahideen Bangladesh, which claims to represent Islamic State in Bangladesh but has no proven links to it.

Islamic State also claimed responsibility for two bombings overnight in Baghdad that killed nearly 120 people and wounded 200, most of them in a busy shopping area while residents celebrated the Muslim fasting month of Ramadan.

Reacting to the two attacks over the past three days, Pope Francis asked people attending noon prayer at the Vatican in Rome to pray for the victims and their families.

Late on Sunday in Bangladesh, hundreds of men, women and children held a candle light vigil near Dhaka's Shaheed Minar (Martyr's Monument) to pay respect to those who lost their lives.

“We don't want this,” Nasima, a textile industry worker, told Reuters Television. “Please stop this, stop this, stop this from our society, from our country, I want to live in peace.”

As Dhaka limped back to normal life, security experts questioned the delay in launching the offensive against the militants. More than 100 commandos stormed the restaurant nearly 10 hours after the siege began, under an operation code-named 'Thunderbolt'.

Analysts say that as Islamic State loses territory in Iraq and Syria and its finances get drained, it may be trying to build affiliates in countries such as Bangladesh for jihadists to launch attacks locally and cheaply.

RICH FAMILIES

Deputy Inspector General of Police Shahidur Rahman told Reuters on Sunday that authorities were investigating any connection between the attackers and transnational groups such as Islamic State or al Qaeda.

He said the militants were mostly educated and from well-off families, but declined to give any more details.

National police chief Shahidul Hoque said all the gunmen were Bangladeshis. “Five of them were listed as militants and law enforcers made several drives to arrest them,” he said.

Whoever was responsible, the attack marked a major escalation in violence by militants demanding Islamic rule in Bangladesh, whose 160 million people are mostly Muslim.

Previous attacks have mostly singled out individuals advocating a secular or liberal lifestyle, or religious minorities.

RECITING KORAN VERSE

Friday night's attack, during the final days of Ramadan, was more coordinated than the previous assaults.

Gunmen singled out foreigners as soon as they stormed through the doors of the restaurant popular with expatriates. They ordered all Bangladeshis to stand up before the killing began, a source briefed on the investigation said.

The Bangladeshis were later told to close their eyes and recite verses from the Koran. One militant cursed a Bangladeshi for eating with non-Muslims during Ramadan, the source said.

The Islamic State-affiliated Amaq news agency claimed in a report on Saturday that the militants identified and released Muslim patrons from the Dhaka restaurant, SITE said.

The victims also included at least three Bangladeshis or people of Bangladeshi descent.

The militants hacked most of their victims with machetes, leaving their bleeding bodies on the floor.

A standoff of nearly 12 hours with security forces ended when the commandos stormed the building, killing six of the militants and capturing a seventh after attempts at negotiations proved fruitless, authorities said. They recovered explosives and sharp weapons from the scene.

It was not clear if the attackers had made any demands.

HOME-GROWN GROUPS

Up until Friday's attack, authorities had maintained no operational links existed between Bangladeshi militants and international jihadi networks. Bangladesh has blamed JMB and another home-grown outfit for the wave of grisly killings over the past year and a half.

One line of inquiry being pursued was whether the restaurant attackers received any guidance from Islamic State or al Qaeda, an official in Bangladesh's counter-terrorism wing said.

“Pictures (uploaded on Twitter) indicate they might have been encouraged by ISIS (Islamic State) activities abroad,” said Muhammad Zamir, a former senior foreign ministry official.

“But this does not show a direct link to ISIS. This is exactly what was done and disputed later in the case of the Orlando attack,” he said, referring to the killing of 49 people last month by a man who pledged allegiance to Islamic State.

Friday's attack in Dhaka was the worst since 2005, when JMB set off a series of bombs throughout Bangladesh in the space of an hour that killed at least 25 people, mostly judges, police and journalists.

The authorities executed six top JMB leaders in March 2007 and police have continued to hunt for group members, often detaining suspected militants following intelligence tips.

In February, Bangladesh police arrested three JMB members suspected of killing a Hindu priest.

Islamic state has claimed responsibility for a series of other attacks in Bangladesh in recent months since first taking credit for a killing in September last year.

An Italian missionary was shot and wounded in the neck last November. Another Italian and a Japanese citizen were killed in attacks at the end of September and early October last year.

“SAVE ME, SAVE ME"

In a run-down government hospital in Dhaka, two police officers who were on patrol duty on Friday night were treated for gunshot wounds, with bandages and plasters on their cheeks and legs. Behind their beds, a sheet of paper carried details of their wounds.

Struggling to speak, 30-year-old officer Pradip, who gave just one name, recalled rushing to the spot after receiving a message that night. A blood-smeared man lay in front of the restaurant, shouting “save me, save me".

The police officers called for backup after they were shot at from inside the restaurant.

“At some point, I felt blood was rolling down my cheek," Pradip said. “We did respond with fire and the attackers stopped. We then rescued the man, who was the driver of some of the Japanese citizens who were inside.”

After meeting the officers in the hospital, police chief Hoque told Reuters they had gleaned some preliminary details on the identities of the attackers, but gave no details.

GARMENT INDUSTRY

The seven Japanese killed were working on projects for the Japan International Cooperation Agency, an overseas aid agency, Japan's Chief Cabinet Secretary Yoshihide Suga said on Saturday.

Six of them were in Dhaka to work on a metro rail project, said Bangladesh's communication minister Obaidul Quader.

Italian media said several of the Italians victims worked in Bangladesh's $26 billion garment sector, which accounts for 80 per cent of the country's exports.

A Bangladeshi garment exporter who supplies six European countries said his customers generally visit every two months but will now rethink that.

“I feel they will be afraid,” he said, declining to be identified. “Even I am afraid.”