The statement from Al-Qaida in the Islamic Maghreb did not elaborate, but it suggests that Spain paid a ransom. The Spanish government has declined comment on a report in the newspaper El Mundo that euro3.8 million ($4.83 million) in ransom was paid.
Monday's release came just days after a Malian who was sentenced in Mauritania for the kidnapping was extradited back to his home country. The al-Qaida affiliate had demanded his return as a condition for the release of the two aid workers.
Spanish newspaper El Pais said Tuesday it received the statement in an audio clip.
The statement says Spanish hostages Albert Vilalta and Roque Pascual "were set free in return for responding to some of our demands."
Pascual and Vilalta arrived back home in Barcelona early Tuesday. They were kidnapped in Mauritania in late November while riding in a convoy delivering supplies to poor villages.
The statement says the release of the two Spaniards should be a lesson to France — which mounted a failed military attempt last month to free a French hostage held by the group.
That raid, mounted with Mauritanian forces, left six militants dead. In retaliation, Al-Qaida in the Islamic Maghreb later executed the hostage, ailing 78-year-old aid worker Michel Germaneau.
"This is a lesson the French politicians should comprehend very well in the future," the statement said. "It was possible to deal rationally with the Mujahedeen. It was possible to avoid the aggravation, irritation and anger that led to the killing of their national."