Morocco's King Mohamad VI released 48 Spanish prisoners in the wake of a recent visit by King Juan Carlos of Spain to the country.
Among these prisoners was a Spanish paedophile convicted of raping 11 children.
The decision to release the man unleashed a storm of protest in the north African county with protests taking place across the country.
Moroccan police on Friday dispersed a crowd of several thousand people in Rabat protesting against a royal pardon.
Dozens of people including photographers and reporters were injured in clashes with authorities, who stepped in to prevent the protest in front of the parliament building in the capital Rabat.
Protesters slammed the pardon as "an international shame" with one demonstrator saying the state "defends the rape of Moroccan children".
But new reports suggest the 60-year-old man may have actually been a spy.
"The paedophile was released on the request of Spain's secret services," Morocco's Lakome news site reported on Friday, citing Moroccan sources close to the matter.
Spain's Justice Minister Mustapha Ramid confirmed in a statement that the prisoner had been freed for "reasons of national security".
This "was current practice between friendly nations," the statement added.
"This (pardon) was an agreement between the DGED (the Moroccan secret service) and it's Spanish equivalent, the National Intelligence Centre (CNI)," a Moroccan source told El Pais.
"The Spaniards insisted that he be put in the list and they achieved this," the source told the Spanish paper.
According to El Pais, the convicted paedophile told his lawyer, Mohamed Benjedou, that he was an official of the Iraqi army who had collaborated with foreign secret services in the downfall of Sadam Hussein.
But the lawyer also told the daily the man had worked as professor of Ocean Sciences at Spain's Murcia University.
"I didn't believe him because it's impossible he did both those things at the same time in places so far apart," Benjedou said.
El Pais also reported that the name being given to the paedophile was probably not his real name.
The paper said the man had been born in the Iraqi city of Basra in 1950 to Iraqi parents.
In Moroccan penal documentation, he was listed as a "Spaniard of Iraqi origin".
The name the paedophile was going by could have been a name made up by Spanish secret services when they extracted him from Iraq and provided him with document saying he was a retired professor from Murcia, the Spanish paper suggested.
A search by the daily found no sign of man going by the paedophile's name among databases of the Spanish education system.
El Pais said the man had probably provided intelligence on Iraq over a long period to Spain's security services or to other intelligence agencies.
This was why CNI had pushed for his release, the centre-left daily argued.
The Spanish paedophile was released on Morocco's annual Throne Day, which celebrates Morocco's ruling family.
The royal family of the north African country have remained silent about the scandal, which the Lakome new site has chosen to label DanielGate, a reference to the paedophile's first name.
One young woman at Friday's protests against the paedophile's release told AFP: "This is the first time I have been to a demonstration because I am outraged by this pardon which has set this paedophile free."
Hakim Sikouk, who also took part in the Rabat protest, told AFP: "I was with a group of friends in front of the parliament when the police intervened violently. I was hit on the head."
Similar demonstrations were broken up earlier Friday in the northern cities of Tangiers and Tetouan.
In June, thousands of Moroccans marched in Casablanca to condemn paedophilia and violence against children in the north African country.
On June 20, police arrested a suspected British paedophile after local residents overheard the screams from a six-year-old girl he allegedly abducted.
And in May, a Casablanca court jailed a 60-year-old Frenchman for 12 years after convicting him of paedophilia.
Abdelali Hamiddine, a senior member of the ruling moderate Islamist Party of Justice and Development, said the pardon was a "mistake".
"Moroccans have the right to demonstrate when they feel humiliated and the authorities do not have the right to step in so violently," he added.