Bangladeshi PM Sheikh Hasina said 13 hostages were freed and six attackers shot dead. One of the gunmen was arrested, she said.
Some of those who were held at the cafe were believed to be Italian and Japanese.
ISIS has said it carried out the attack.
The 12-hour siege began as diners were gathering to break their fast during the Muslim holy month of Ramadan.
In a TV statement, PM Sheikh Hasina said: “It was an extremely heinous act.
“What kind of Muslims are these people? They don’t have any religion.
“My government is determined to root out terrorism and militancy from Bangladesh.”
Japan’s Deputy Chief Cabinet Secretary Koichi Hagiuda said one Japanese citizen was shot and wounded in the attack, and that seven others were in the cafe. Japan’s government has not yet been able to contact them, he said.
Bangladesh’s Daily Star newspaper said the gunmen tortured anyone who was unable to recite the Koran. They provided meals overnight for only the Bangladeshi captives, the Daily Star said.
Sumon Reza, a supervisor at the cafe, was in the restaurant when the attack began but managed to flee to the roof.
“The whole building was shaking when they set off explosives,” he told media in Bangladesh. He later jumped off the roof and escaped.
Explosions and heavy gunfire were heard earlier, as the army and navy commandos stormed the cafe.
Armored vehicles were also seen moving in the Gulshan neighborhood.
The gunfire stopped after about an hour.
The identity of the rescued hostages and the fate of other captives believed to have been in the cafe were not immediately known.
At least two police officers were killed in exchanges of fire on July 1, and 30 police officers were injured.
The attack began when eight or nine armed men burst into the cafe in the diplomatic area of Dhaka at about 21:20 on July 1 and opened fire.
A statement on the ISIS’ self-styled Amaq news agency said militants had attacked a restaurant “frequented by foreigners”. It said that more than 20 people “of different nationalities” had been killed but this has not been confirmed.
Seven Italian nationals are believed to have been in the cafe, the Italian ambassador in Dhaka, Mario Palma, was quoted as saying by Italian media.
Lt. Col. Tuhin Mohammad Masud, commander of the Rapid Action Battalion, told Associated Press the gunmen did not respond when asked to negotiate. It is unclear if they made any demands.
The attack comes after a spate of murders of secular bloggers, gay activists, academics and members of religious minorities, blamed on Islamist militants.
Holey Artisan Bakery is described as being popular with expats, diplomats and middle-class families.
Media reports quoted witnesses as saying that “Allahu Akbar”, meaning “God is great”, was heard as the militants entered the cafe.
Image source: Wikimedia Commons President-elect Donald Trump celebrated his election victory at the Ultimate Fighting…
Millions of voters across the US chose to return Donald Trump to the White House…
Donald Trump declares victory in the US election as he addresses jubilant supporters in Florida.…
Stocks around the world are rising as Donald Trump appears to be on the cusp…
Donald Trump has won Pennsylvania, North Carolina and Georgia and taken a lead over Kamala…
Quincy Jones, the celebrated musician and producer who worked with Michael Jackson, Frank Sinatra, Ray…