Gunmen stormed a restaurant popular with expats in the diplomatic quarter of the Bangladeshi capital and took about 20 people hostage, including several foreigners, in an attack claimed by the so-called Islamic State.
The Islamist militant group said more than 20 people had been killed, although police have so far only confirmed the deaths of two policemen.
In the latest flare-up of Islamist militant violence to hit the South Asian nation, police said eight to nine gunmen attacked the Holey Artisan restaurant in the upscale Gulshan area of Dhaka.
The assailants, believed to be carrying assault rifles and grenades, exchanged sporadic fire with police outside, hours after the attack began around 9pm local time.
Two police officials died in the attack and at least 15 people were injured, police said. A duty officer at the Rapid Action Battalion's control room in Dhaka said the gun battles had stopped and the hostages were unharmed.
"We are discussing ways to rescue the people, including foreigners, who are inside the cafe," police official Mohammad Habibur Rahman said.
"Our priority is to rescue them peacefully without the loss of any life."
Earlier, Benjir Ahmed, the chief of Bangladesh's special police force, said police were preparing to launch an operation to rescue those being held captive. Mr Ahmed said the attackers had hurled bombs at police.
Television footage showed a number of police being led away from the site with blood on their faces and clothes. Heavily armed officers could be seen milling outside.

A resident near the scene of the attack said he could hear sporadic gunfire nearly three hours after the attack began.
"It is chaos out there. The streets are blocked. There are dozens of police commandos," said Tarique Mir.
Bangladesh has seen an increase in militant violence in the last year-and-a-half, with a series of deadly attacks targeting atheists, gays, liberals, foreigners and members of religious minorities in the mostly Muslim country of 160 million people.
They have tended to be assaults on individuals, often using machetes, and the raid on the restaurant is a rare instance of a more coordinated operation.
Both IS and al Qaeda have claimed responsibility for many of the killings, although local authorities say there are no operational links between Bangladeshi militants and international jihadi networks.
