Agreement before UN-sponsored summit on migration in Morocco next month
Spain hails joint co-operation with Morocco on controlling migration
Spain has demanded the EU unlock development funds to assist Morocco's efforts to staunch the flow of migration across the Mediterranean.
Pedro Sanchez, the Spanish prime minister, used his first visit to the North African kingdom to seek a common stance with Saad Eddine El Othmani, his opposite number, on controlling migration.
"Migration is a shared responsibility, and we need to strengthen our co-operation," Mr Sanchez said at the end of the trip.
Mr Othmani said Morocco "is doing everything in its power" to fight illegal immigration and insisted the complex issue "cannot be solved solely by the security approach".
"Despite the importance of security, we must focus on the development of countries of departure in Africa," he said.
Many migrants in Morocco who embark for Spain are sub-Saharan Africans.
Moroccan authorities say that between January and the end of September they stopped about 68,000 illegal attempts to cross into Europe, and dismantled 122 people smuggling gangs. Last year, the kingdom prevented 65,000 migrants from crossing to Spain, officials said.
Despite pressure from Brussels, Morocco says it cannot be the region's immigration police and insisted on development plans being funded as part of joint efforts.
Morocco's place as a point of passage has grown with Italy's refusal to take in migrants who try to cross the Mediterranean Sea from Libya. The Libyan coastguard, with help from the Italian government, increasingly has intercepted flimsy boats launched by migrant smugglers.
Migrants head to northern Morocco with the aim of crossing the Strait of Gibraltar to Spain or climbing over high fences to reach the Spanish enclaves in North Africa, Ceuta and Melilla.
Nearly 47,500 migrants arrived in Spain by sea since the start of the year, while 564 died or went missing while attempting the voyage, according to the International Organisation of Migration.
Moroccan police conduct regular raids of areas popular with people from elsewhere in Africa and have moved thousands by bus to the other end of the country since 800 people stormed a fence to the Spanish enclave of Ceuta in northern Morocco in July.
Yet Morocco, along with Tunisia and Algeria, has rejected attempts by the EU to persuade North African countries to serve as an immigration reception and processing centre. Morocco instead wants more EU funding to help manage migration across its borders, especially in addressing push factors that prompt migrants from Sub-Saharan Africa use Morocco as a jumping off point.
Morocco is scheduled to host the international conference on migration in December.
Mr Sanchez also said he wanted to promote a joint bid between his country, Portugal and Morocco to host the 2030 World Cup.
"I made the proposal, firstly to the government then to King Mohammed VI to launch a shared application with Morocco, Portugal and Spain to host the 2030 World Cup," Mr Sanchez said in Rabat.
"It will be the first two-continent application, with Europe and Africa, and King Mohammed VI welcomed the proposal warmly."