Spain has this year become the main entry point for migrants crossing the Mediterranean, the majority departing from Morocco.
“Migration is a shared responsibility and we must reinforce our cooperation in this area,” Sanchez said following talks with his Moroccan counterpart Saad Eddine el Othmani.
More than 50,000 migrants have crossed into Spain so far this year, according to figures from the International Organization for Migration (IOM).
Madrid has for months been pressing the European Union to unlock funds for Morocco to better tackle people smuggling into the bloc.
Throughout the year, numerous Spanish ministers and officials have travelled to Rabat to discuss security issues and migration.
Sanchez was accompanied by a government delegation for his first visit to the North African nation since taking office in June.
Othmani said Morocco was doing “all that is in its power regarding the fight against illegal immigration”.
Moroccan authorities say that between January and the end of September they stopped some 68,000 illegal attempts to cross into Europe and dismantled 122 people smuggling gangs.
“The migration question is complex and it cannot be resolved solely through a security approach, despite its importance, it's necessary to favour the development of departure countries in Africa,” said Othmani.
Many seeking to reach Europe are from sub-Saharan Africa, but in recent years there has been an increasing number of Moroccans seeking to leave the country.
While the majority of migrants have taken the perilous sea journey in rubber dinghies, others have scaled fences into the Spanish territories of Ceuta and Melilla which border Morocco.