At least nine Algerian soldiers were killed when Islamist militants ambushed their patrol west of the capital Algiers last week in one of the deadliest attacks in months, the Defense Ministry said on Sunday.
Al-Qaida in the Islamic Maghreb claimed Friday's attack in the Ain Defla region in a statement posted on a social media account that often releases its communiques.
A security source on Saturday had said 11 soldiers were killed. Sunday's statement from the ministry was the first official confirmation of the attack.
"A detachment of the army was targeted by a terrorist group. We deplore the death of nine soldiers as martyrs and two injured," the ministry statement said.
Since Algeria's conflict with armed Islamists in the 1990s in which more than 200,000 people were killed, it has become one of North Africa's most stable states and is a key ally in the Western campaign against Islamist militancy in the region.
But al-Qaida-allied fighters under veteran commander Abdelmalek Droukdel, and rival fighters who split to declare loyalty to Islamic State, are still active in pockets of the country, mostly in remote mountain areas.
One security source said Droukdel may have been involved in the ambush as a way to show al-Qaida presence on the ground.
Gunmen claiming loyalty to Islamic State, which controls swathes of Iraq and parts of Syria, have been gaining ground in neighboring Libya, where a conflict between two rival governments has created a security vacuum.
Islamic State has claimed two major attacks on foreign tourists in Tunisia. Authorities say gunmen in the Sousse beach resort attack last month and the March gun assault on the Bardo museum in Tunis were trained in jihadi camps in Libya.
But an al-Qaida-allied group Okba Ibn Nafaa has been the most active, mostly along the border with Algeria, carrying out attacks on the military and police. It was also blamed by government for the Bardo attack.
The Islamic State splinter group in Algeria, known as the Caliphate Soldiers, has been decimated by a security crackdown since it beheaded a French tourist late last year.