Islamic gunmen shouting "Allahu Akbar" attacked an upscale cafe in the Bangladeshi capital, killing 20 people inside, before police stormed the building and rescued 13 hostages, officials say.
A Bangladesh Army spokesman says all 20 victims of the attack were foreigners.
Six gunmen were killed during the police operation and one was captured, Prime Minister Sheikh Hasina said in a TV broadcast on Saturday.
"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 (local time). 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.
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.
IS posted photos of what it said were dead foreigners killed in the assault.
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, told Reuters 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.