"The operation is over," said Brig. Gen. Mujibur Rahman, who was overseeing the troops in the rescue effort at Holey Artisan Bakery, which was raided by gunmen Friday night.
Its unclear how many people the gunmen seized in the cafe at a diplomatic zone, but Rahman said 14 hostages were rescued.
Bangladesh Prime Minister Sheikh Hasina provided a different number.
"We were able to save 13 people ... and of these terrorists six of them died on the spot, they died right there," Hasina said at a news conference.
She said one of the terrorists was captured alive.
Before the siege ended, witness Fayad Munaim said he heard heavy gunfire after hours of quiet in the area. The shots lasted about 10 minutes then stopped, he said.
ISIS has claimed responsibility for the terror attack, according to its media branch, Amaq. Some U.S. officials have cast doubt on the claim.
Here's what we have so far:
• Gunmen attacked the cafe popular with expats and took those inside hostage, cafe worker Sumon Reza said.
Reza said he escaped as six to eight gunmen entered. About 20 people, some of them foreigners, were in the restaurant.
• A police officer in charge of a nearby station was shot dead, Maruf Hasan of Dhaka Metropolitan Police said. A second officer died from gunshot wounds, Detective Police Deputy Commissioner Sheikh Nazmul Alam said.
• Alam said 40 people were wounded, some by gunshots and others by shrapnel from explosive devices.
• Ataur Rahman, who was in his office about 200 meters from the restaurant, said he went to the street as he heard a series of gunshots. "I thought it might be an attack somewhere nearby by local thugs." He said people were racing for cover, saying gunmen were shouting "Allahu Akbar."
• Police are trying to find out the demands of the gunmen holding customers. The gunmen have not made any demands.
• The U.S. Embassy in Dhaka said it had accounted for all of the American citizens working under the chief of the mission authority.
The embassy and many other diplomatic missions are less than 1.5 kilometers (.9 miles) from the cafe.
• The Islamic State (ISIS) has claimed a number of past attacks in Bangladesh through its media affiliates, but the government has consistently denied any ISIS presence in the country. Other attacks have been claimed by local Islamist groups.
• Though there was the reported ISIS claim of responsibility, the U.S. State Department said it cannot yet be confirmed. Spokesman John Kirby said the State Department is assessing information.
• A U.S. official familiar with intelligence thinking told CNN's Barbara Starr that based on past operations, it is more likely that al Qaeda in the Indian Subcontinent is conducting this attack -- not ISIS. This is preliminary analysis -- not a conclusion -- based on the best information available. The official says AQIS has demonstrated a more capable presence in Dhaka over the past few months than ISIS, and so far, all of its attacks in Bangladesh have been in Dhaka.
Lori Ann Walsh Imdad, an American teacher living in Dhaka, said she lives one block from the restaurant. She said she heard a burst of gunfire first; after that it was sporadic.
Farzana Azim says she heard explosions outside her home. "We heard the first bomb blast at 8:30 in the evening," Azim said. At first she thought it was the sound of a plane, but a few minutes later another blast echoed through the neighborhood of Gulshan. Within a half hour, the gunshots started, she said.
I never thought something like this could happen. It is next to a small hospital. This is family-friendly restaurant. Everyone loves to go there," she said. She said her husband and son had gone outside for the call to prayer and the attack happened shortly after that.
Friday's terror attack comes as the holy month of Ramadan, in which Muslims fast from sunrise to sunset, nears its end. Bangladesh is 89% Muslim, according to the CIA Factbook.
ISIS or al Qaeda?
CNN terrorism analyst Peter Bergen said he is unaware of an ISIS claim of responsibility that has been proven wrong.
Bergen said he had talked to a counterterrorism official who thought ISIS was to blame for the attack, and that was before the media arm made its announcement. The official said al Qaeda typically doesn't conduct operations with teams this large.
Philip Mudd, a former CIA counterterrorism official and a CNN analyst, agreed with Bergen that ISIS doesn't issue false claims. He said he thinks they were quick to take credit for the attack before al Qaeda could.
"As they compete, they want to get out there in a place like Bangladesh right away before al Qaeda says anything and they say this is us," Mudd said.
ISIS and al Qaeda want to expand their presence around the world, Bergen said. That includes taking homegrown terror groups and making them affiliates.
Wave of killings
The attack came on the same day a Hindu priest was hacked to death at his temple
in Bangladesh's southwestern district of Jhenaidah, police said.
That incident was the latest in a wave of killings across Bangladesh of secular bloggers, academics and religious minorities such as Hindus, Christians, Buddhists and Sufi Muslims -- despite a nationwide government crackdown and the arrest of more than 14,000 people.
The government launched an anti-militant drive across the Muslim-majority nation last month to stamp out the murders, but many of those detained are believed to be ordinary criminals and not Islamic extremists.
Home to almost 150 million Muslims, the country until recently had avoided the kind of radicalism plaguing others parts of the world. But that's changing as the attacks seem designed to silence those to dare to criticize Islam.
One high-profile killing was the murder of Bangladeshi-American writer Avijit Roy
in 2014 that occurred right outside Dhaka's annual book fair. In April, a well-known LGBT activist and his friend were murdered.