Morocco's king has strongly condemned the visit by the Spanish monarch to the disputed Spanish enclaves of Ceuta and Melilla on the north Moroccan coast.
The Moroccan king said Juan Carlos's visit was counterproductive
King Mohammed VI said it had hurt the feelings of the Moroccan people.
In a rare statement to cabinet, he said the unprecedented visit by King Juan Carlos was offensive and jeopardised future relations between the countries.
Morocco has long been demanding control over the two enclaves, which have been Spanish for some 400 years.
This is the first time the Spanish king has visited Ceuta and Melilla as head of state in his 32-year reign.
Morocco withdrew its ambassador from Madrid in protest.
"We emphatically condemn and strongly denounce such an unprecedented visit, a counterproductive step that hurt the deep patriotic feelings of the whole Moroccan people," King Mohammed said in a statement, Reuters news agency reports.
There have been protests on the Moroccan side of the enclaves
But AP news agency says the monarch also called for dialogue "that guarantees our sovereignty rights and which take Spain's interests into account".
Correspondents say during the visit, thousands of the enclaves' residents turned out to greet the Spanish royal couple, waving Spanish flags and shouting, "We are Spanish".
But there were protests against the tour at the border posts of both Ceuta and Melilla with Morocco.
High-level Spanish visits to the two strategic enclaves are rare.
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.