OUAGADOUGOU, Burkina Faso — Gunmen from Al Qaeda stormed a luxury hotel frequented by foreigners in Burkina Faso’s capital on Friday night, seizing hostages and killing others while fighting with dozens of security forces who began a counterattack hours later. It was Al Qaeda’s first major attack in this landlocked sub-Saharan country, a former French colony.

Burkina Faso’s interior minister, Simon Compaoré, said Saturday morning that after an overnight battle, security forces had regained control of the Splendid Hotel in the capital, Ouagadougou (pronounced waga-DOO-goo), having killed at least three assailants and freed 126 people. A spokesman for the interior ministry, Abi Ouattara, said 22 people had been killed, not counting the militants killed by security forces.

The attack, claimed by the Al Qaeda in the Islamic Maghreb affiliate along with an allied militant group, was at least the fifth time in recent days that armed militants had ambushed unprotected civilians in cities around the world, hitting sites in Turkey, Egypt, Indonesia and Iraq with deadly assaults that underscored the vulnerabilities of soft targets that are difficult to defend.

Witnesses said the attack began when gunmen set off at least one explosion outside the hotel, leaving cars ablaze, and then moved inside and began taking hostages. Hours later in a statement released online, Al Qaeda in the Islamic Maghreb said its fighters inside the hotel had killed 30 people, calling their operation “revenge against France and the disbelieving West,” according to a translation by the SITE Intelligence Group, which monitors jihadist media.

France, which maintains a military garrison in Burkina Faso, scrambled to respond to the siege, sending 30 of its soldiers to assist at least 40 from Burkina Faso’s military who massed outside the hotel. Witnesses reported that the forces began a counterassault to retake the hotel early Saturday. One witness, Olympia de Maismont, said that “several hostages had been freed” and that intermittent gunfire could be heard. Later, Rémis Dandjinou, Burkina Faso’s minister of communication, said that 63 people had been freed, 33 of whom had been wounded.