U.S. and French special operations forces assisted Malian troops in the swift response to the attack by an unknown number of gunmen. Shooting continued into the late afternoon, and a U.N. official said two attackers had been killed.
An extremist group led by former al-Qaida commander Moktar Belmoktar claimed responsibility for the siege at the Radisson Blu hotel in the former French colony, and many in France saw it as a new assault on their country's interests a week after the Paris attacks.
As people ran for their lives near the hotel along a dirt road, troops in full combat gear pointed the way to safety, sometimes escorting civilians with a protective arm around their shoulders. Later, local TV showed heavily armed troops in what appeared to be a lobby, apparently led by an officer.
At least 27 people were killed in the attack, with 12 bodies found in the basement and 15 found on the second floor, a U.N. official said. But the operations were still going on and the hotel had not been totally cleared, added the official, who spoke on condition of anonymity because the operation was still underway.
A Malian military official initially said there were 10 gunmen, but by later in the day, it was not clear how many assailants took part. It also was not known if the attackers were included in the U.N. count of the dead.
Malian special forces went "floor by floor" to free hostages, army Cmdr. Modibo Nama Traore told The Associated Press.
U.S. special forces assisted the Malian troops, said Col. Mark Cheadle of the U.S. Army's Africa Command. At least six Americans were evacuated from the hotel, although it was unclear how many were inside, he added.
About 40 French special police forces played a support role, France's national gendarme service said. The French Defense Ministry said its troops arrived in Bamako to support Malian forces.
About 170 guests and employees were initially taken hostage early Friday, but some apparently escaped in the initial chaos or hid in the sprawling, cream-and-pink hotel that has 190 rooms and a spa, outdoor pool and ballroom.
"It was more like a real terrorist attack," said U.N. Mission spokesman Olivier Salgado. "The intention was clearly to kill, not to necessarily have people being hostage."
Traore said at least one guest reported the attackers instructed him to recite verses from the Quran before he was allowed to leave.
The guests included visitors from France, Belgium, Germany, China, India, Canada, Ivory Coast and Turkey. But the attack was perceived by many in France, particularly in the government, as a new attack on French interests.
An extremist group that two years ago split from al-Qaida's North Africa branch and led by Moktar Belmoktar claimed responsibility for the attack in a recorded statement carried by Al-Jazeera. The group said it wanted fighters freed from Mali's prisons and for attacks against northern Malians to stop.
The jihadist group, known as the Mourabitounes, was formed in 2013 after Belmoktar left al-Qaida in the Islamic Maghreb and fused with a Malian militant group. The statement issued Friday said the Mourabitounes had attacked in coordination with the "Sahara Emirate" affiliated with al-Qaida.
The French military operation in Mali in 2013 against Islamic extremists who were holding the northern half of the country was the first of several foreign interventions that President Francois Hollande has launched as president. Those interventions have prompted increased threats against France and French interests from Islamic extremist groups from al-Qaida's North African arm to the Islamic State group.
"We should yet again stand firm and show our solidarity with a friendly country, Mali," Hollande said.
French news websites and all-news TV networks immediately switched from nearly nonstop coverage of the Paris attacks investigation and aftermath to Bamako siege.
"This could be a strike at important French interests because the French government invested so much military energy in pushing the Islamic rebels out of Mali," said Jens David Ohlin, an international law expert at Cornell University. "While Mali might not have the same emotional significance to the French as Paris does, it is certainly an important part of the French military strategy."
President Barack Obama said he was monitoring the situation.
The gunmen had stormed the hotel shouting "God is great," in Arabic before firing on the guards, Traore said. An employee who gave his name as Tamba Diarra said by phone while the attack was in progress that the militants used grenades.
Ambulances rushed to the hotel and a military helicopter flew overhead.
Monique Kouame Affoue Ekonde, from Ivory Coast, said she and six other people, including a Turkish woman, were escorted out by security forces as the gunmen rushed toward the fifth or sixth floor.
She added that she was "in a state of shock."
Belgian Foreign Minister Didier Reynders said four Belgians had been registered at the hotel.
Chinese state broadcaster CCTV, citing its diplomats in Mali, reported about 10 Chinese citizens took shelter in their rooms, and all were reported safe. All are employees of Chinese companies working in Mali.
Also reported safe were 12 members of an Air France flight crew and five from Turkish Airlines. All 20 guests from India were safely evacuated as well, said Vikas Swarup, spokesman for India's Foreign Ministry.
The U.N. mission sent security reinforcements and medical aid to the scene, said U.N. deputy spokesman Farhan Haq. He said the United Nations had a few staff members in the hotel but they were all safely out.
Northern Mali remains insecure and militant attacks have extended farther south this year, including the capital. In March masked gunmen shot up a restaurant in Bamako that is popular with foreigners, killing five people.
France has 3,500 troops operating in Mali and four other countries in the Sahel region as part of a five-nation counterterrorism operation. The ministry did not specify how many soldiers were sent to Bamako.
The Netherlands also has troops working with the U.N. mission. According to the Dutch defense ministry, some 450 Dutch military personnel are taking part in the mission along with four Apache and three Chinook helicopters. Most of the Dutch force is based in Gao, but there are a few officers at the U.N. mission headquarters in Bamako.