Albert Vilalta and Roque Pascual were among three workers with the non-governmental organization Accio Solidaria abducted and handed over to al-Qaida in November in Mauritania.
Spanish Prime Minister Jose Luis Rodriguez Zapatero said the release brings a long ordeal to a safe conclusion.
"They are safe and sound after 268 days in the hands of their kidnappers," he was quoted Monday by al-Jazeera as saying.
Arab media during the weekend said the captives' release was connected to the return to Mali from Mauritania of Omar Sid'Ahmed Ould Hamma, who was allegedly tied to the kidnapping.
Al-Qaida in the Islamic Meghreb said in early August it would execute the Spaniards.
The North African terrorist group said Spain was a target because of its friendly ties to Washington and NATO.
A third worker from Accio Solidaria was released in March.
Celebrity Couples of 2014 [PHOTOS]