Islamic gunmen shouting "Allahu Akbar" attacked an upscale cafe in the Bangladeshi capital, killing 20 people inside, before police stormed the building on Saturday and rescued 13 hostages, officials said.
The attack, claimed by Islamic State, marks a major escalation in a campaign by Islamic militants over the past 18 months that had targeted mostly individuals advocating a secular or liberal approach in mostly Muslim Bangladesh.
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 after a 12-hour siege that began when gunmen stormed the restaurant on Friday night. Two police were killed in the initial assault.
The 13 hostages that were rescued included one Japanese and two Sri Lankans, Chowdhury told a news conference. Police said earlier the gunmen were holding about 20 hostages.
One Japanese man was among those rescued and taken to a Dhaka hospital with a gunshot wound, a Japanese government spokesman said. Seven Japanese were unaccounted for.
Italy's ambassador to Bangladesh, Mario Palma, told Italian state TV seven Italians were among the hostages.
Islamic State posted photos of what it said were dead foreigners killed in the assault, which could deal a major blow to the country's vital $25 billion garment sector.
Police said they believed about eight to nine gunmen had been holed up in the cafe, armed with assault rifles and grenades.
Gowher Rizvi, an adviser to Hasina, said security forces had tried to negotiate with the gunmen.
The hostage crisis began when security guards in the Gulshan district of Dhaka, popular with expatriates, noticed several gunmen outside a medical centre, Rizvi said. When the guards approached, the gunmen ran into the Holey Artisan cafe, which was packed with people waiting for tables, he said.
Ali Arsalan, co-owner of the restaurant, said that his staff told him the attackers yelled "Allahu Akbar" (God is Great) as they stormed the building
Police said the assailants exchanged sporadic gunfire with police outside for several hours after the gunmen attacked the restaurant around 9pm on Friday.
A police officer at the scene said that when security forces tried to enter the premises at the beginning of the siege they were met with a hail of bullets and grenades that killed at least two of them.
Television footage showed a number of police being led away from the site with blood on their faces and clothes.
A cafe employee who escaped told local television about 20 customers were in the restaurant at the time, most of them foreigners. Some 15 to 20 staff were working at the restaurant, the employee said.
The rescued Japanese man was eating dinner with seven other Japanese, all of whom were consultants for Japan's foreign aid agency, the Japanese government spokesman said. He did not know what happened to the others.
Spate of murders
The hostage crisis marks an escalation from a recent spate of murders claimed by Islamic State and al Qaeda on liberals, gays, foreigners and religious minorities.
A Hindu priest was hacked to death on Friday at a temple in Jhinaidah district, 300 km (188 miles) southwest of Dhaka.
Both Islamic State and al Qaeda have claimed responsibility for many of the killings, although local authorities say no operational links exist between Bangladeshi militants and international jihadi networks.
Bangladesh security officials say two local militant groups, Ansar-al-Islam and Jamaat-ul-Mujahideen, have been behind the spate of violence over the past 18 months. Ansar pledges allegiance to al Qaeda, while Jamaat-ul-Mujahideen claims it represents Islamic State.
"The bottom line is Bangladesh has plenty of local, often unaffiliated, militants and radicals happy to stage attacks in ISIS's name," said Michael Kugelman, South Asia associate at The Wilson Centre in Washington D.C., using an acronym commonly used for Islamic State.
Islamic State had claimed more attacks in Bangladesh than in Pakistan or Afghanistan, he said.
The restaurant assault also comes after Bangladesh hanged an Islamist party leader, Motiur Rahman Nizami, on May 11 for genocide and other crimes committed during a 1971 war of independence from Pakistan. That has drawn an angry reaction and some scattered violence from supporters. Nizami, 73, was a former legislator and minister during opposition leader Khaleda Zia's last term as prime minister.
Foreign diplomats and human rights groups have warned that Bangladesh's ongoing war crime tribunals and the government's pressure on the Bangladesh Nationalist Party have created a backlash domestically, according to Brad Adams, Asia director at Human Rights Watch.
"They need to maintain legal political space for Jamaat and the BNP so that they don't drive people into the shadows and violence," Adams said in a telephone interview, cautioning that it's not known whether that dynamic and the bloodshed in Dhaka were related.