A Moroccan senator protesting about the King of Spain's visit to the Spanish-held enclave of Melilla has been briefly held by Spanish police.
There have been protests on the Moroccan side of the enclaves
Yahia Yahia was arrested and then freed after several hours, Morocco's official news agency reports.
King Juan Carlos was greeted by thousands of Melilla's residents waving Spanish flags a day after his visit to nearby Ceuta, another Spanish enclave.
Morocco's prime minister has criticised the controversial visits.
Prime Minister Abbas el Fassi told parliament on Monday that Spain should understand that the era of colonialism had passed and the return of Ceuta and Melilla should be directly negotiated.
Ceuta and Melilla, on Morocco's coast, came under Spanish control about 500 years ago but Morocco claims them too.
The Moroccan senator was taking part in a protest against the visit at the territory's border post with Morocco.
This is the king's first visit to the enclaves in his 32-year reign
In Melilla, thousands waving Spain's red-and-yellow flag packed the town's main square and shouting, "Ole! Ole! Ole! We are Spanish!", AP news agency reports.
High-level Spanish visits to the two strategic enclaves are rare. This is the first time the king has visited as head of state in his 32-year reign.
When Prime Minister Jose Luis Rodriguez Zapatero went there in 2006 it was the first by a Spanish head of government since 1981.
Madrid says the urban enclaves are integral parts of Spain.
They are surrounded by Morocco, which views the Spanish presence as anachronistic and claims sovereignty.