Gunmen stormed a restaurant popular with expatriates in the diplomatic quarter of the Bangladeshi capital on Friday night and took about 20 people hostage, including several foreigners, in an attack claimed by Islamic State.
The Islamist militant group said more than 20 people had been killed, although police have so far 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 9 p.m. 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. 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 told Reuters 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 was a rare instance of a more coordinated operation.
Both Islamic State 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.
Militants killed two foreigners last year, leading several Western firms involved in the country's $25 billion garment sector to temporarily halt visits to Dhaka.
The U.S. State Department said all Americans working at the U.S. mission there had been accounted for. A spokesman said in Washington the situation was "very fluid, very live".
President Barack Obama has also been briefed about the attack, the White House said.
The German embassy in Dhaka is trying to determine if any German citizens were affected by the attack, a spokesman for the German foreign ministry said late Friday.