Six gunmen were killed during the police operation and one was captured, Prime Minister Sheikh Hasina said in a TV broadcast.
The attack has been claimed by the Islamic State.
“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. 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.
Earlier, Islamic State posted photos of what it said were dead foreigners killed in the assault on the cafe, where police believed eight to nine gunmen were holed up and armed with assault rifles and grenades.
Gowher Rizvi, an adviser to Bangladesh Prime Minister Sheikh Hasina, told Reuters that security forces had tried to negotiate a way out of the crisis on Friday.
Police said the gunmen attacked the upscale Holey Artisan restaurant in the Gulshan district of Dhaka, popular with expatriates, in an assault that began around 9 p.m local time on Friday.
The hostage crisis marks an escalation from a recent spate of murders claimed by Islamic State and al Qaeda on liberals, gays, foreigners and religious minorities, and could deal a major blow to the country’s vital $25 billion garment sector. Militant violence has spiked in Bangladesh in the last 18 months. Attacks have tended to be on individuals, often using machetes, and the raid on the restaurant was a rare instance of a more coordinated operation. Earlier on Friday, a Hindu priest was hacked to death at a temple in Jhinaidah district, 300 kms (188 miles) southwest of Dhaka.
Both Islamic State and al Qaeda have claimed responsibility for many of the killings, although local authorities say no operational links exist between Bangladeshi militants and international jihadi networks. Bangladesh security officials say two local militant groups, Ansar-al-Islam and Jamaat-ul-Mujahideen, are behind the violence. Ansar pledges allegiance to al Qaeda, while Jamaat-ul-Mujahideen claims it represents Islamic State.An unknown number of Italians were among hostages who were killed, a source at Italy’s foreign ministry has told Reuters.
According to a report in ‘The Daily Star’, a rescued hostage said that people who could recite a verse from the Quran were spared, others were tortured.