Islamist militants killed 19 people in an attack on a top hotel in the capital of Mali before Malian commandos stormed the building and rescued 170 people, many of them foreigners. Two militants were killed.
President Ibrahim Boubacar Keita announced the death toll and said seven people were wounded in the attack, which has been claimed by jihadist group Al Mourabitoun and al Qaeda in the Islamic Maghreb (AQIM).
France and the US had provided logistical and intelligence support for the operation.
The raid on the Radisson Blu hotel, which lies just west of the city center near government ministries and diplomatic offices in the former French colony, comes a week after Islamic State (ISIS) militants killed 130 people in Paris.
Prior to Malian forces entering the hotel, the gunmen had already released some hostages, including those able to recite verses from the Koran, while others managed to escape or were brought out by security forces.
Mali President Ibrahim Boubacar Keita cut short a trip to a regional summit in Chad in order to return to Mali.
"Tonight the death toll is heavy," Keita said on state television, declaring a 10-day state of emergency and three days of national mourning.
Conflicting reports have emerged about the number of gunmen, with the figure ranging between two and 10. They entered the hotel firing shots and shouting "Allahu Akbar", or "God is great" in Arabic.
Chinese, Turkish and French nationals were among those trapped in the hotel. Air France already canceled its Paris-Bamako flight in the wake of the crisis.
A senior member of the hotel's security detail said two private security guards had been wounded in the early stages of the attack, which began at 7am local time.
It also puts a spotlight on veteran militant leader Mokhtar Belmokhtar, whose group Al Mourabitoun staged the attack months after he was reported killed in an air strike.
The attack ended around 4pm In an earlier report, a UN official said UN peacekeepers searching the hotel made a preliminary count of 27 bodies.
As troops stormed the hotel, state television showed them brandishing AK47s in the lobby. A body lay under a brown blanket at the bottom of a flight of stairs.
The US State Department said one American was killed. The White House said it was working to locate all Americans in Mali, and it offered to help with an investigation and urged its citizens to limit their movements around Bamako.
A man who worked for a Belgian regional parliament was also among the dead, the assembly said. France's Defence Minister Jean-Yves Le Drian said he was not aware of any French nationals killed.
A Turkish official said five of seven Turkish Airlines staff had also managed to flee. The Chinese state news agency Xinhua said three Chinese citizens had been killed in the attack.
Associated Press, Reuters and Agence France-Presse contributed to this report.