Seven militants who killed 20 people at a restaurant in Dhaka were local Bangladeshis and authorities had tried before to arrest five of them, police said, as investigators probed for possible links with international Islamist extremist groups.

The gunmen stormed the upmarket restaurant in the diplomatic zone late on Friday, before killing 20 hostages, including at least nine Italians, seven Japanese and an American.

Islamic State claimed responsibility, warning citizens of "crusader countries" that their citizens would not be safe "as long as their aircraft are killing Muslims", the group said in a statement. It also posted pictures of five fighters it said were involved in the attack. Its claims have not been confirmed.

Security sources said Bangladeshi authorities were investigating any ties between the gunmen and trans-national Islamist extremist groups.

Whoever was responsible, the attack marked a major escalation in violence by militants who have demanded 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.

Friday night's attack was more coordinated. The attackers stormed a restaurant in the diplomatic enclave popular with the expatriate community during the final days of the Muslim fasting month of Ramadan.

They ordered all Bangladeshis to stand up before they began killing foreigners, a source briefed on the investigation said. Most of the victims were hacked with machetes before around 100 commandos entered the building, killing six of the militants and capturing a seventh, after a 12-hour standoff, police said.

It was not clear if the attackers had made any demands during the 12-hour hostage standoff.

"All gunmen were Bangladeshi. Five of them were listed as militants and law enforcers made several drives to arrest them," national police chief Shahidul Hoque told reporters in Dhaka late on Saturday.