A Spanish government delegation met Mauritanian military chiefs late on Thursday to discuss methods to deal with a crisis which the Spanish Red Cross estimates has cost more than 1000 lives since the start of the year.
"The two sides have studied the best ways to handle the migration flows and have adopted a series of measures to tackle this serious humanitarian situation," the two governments said in a joint statement on Friday.
Under the agreement, Spain pledged to help Mauritania build and manage reception centres to receive detained migrants.
The two sides also agreed to launch joint coastal patrols and Spain would give Mauritania four patrol vessels and help train their crews.
Spanish experts would also train Mauritanian security forces to track down migrant-smuggling networks and would give advice on how to detect false identity and travel documents.
Madrid also pledged to ask the European Union to give emergency aid to Mauritania.
Appeal for help
Mauritania had earlier called for international help to stem the exodus from its northern coast, where scores of young men from around West Africa set out every night in rickety fishing boats bound for Spain's Canary Islands almost 800km away.
Yahya Ould Cheikh Mohamed Vall, governor of Mauritania's northern port of Nouadhibou, which has become a hub for migrants in recent months, told the Spanish delegation he needed immediate aid of $230,000 a month.
"The two sides have studied the best ways to handle the migration flows and have adopted a series of measures to tackle this serious humanitarian situation"
Spain and Mauritania
Vall said the money was needed to tighten border controls, build a reception centre for detainees and fight the network of touts and middlemen who organise the migrants' voyages.
He said around 1000 sub-Saharan Africans were arriving in Nouadhibou every month to prepare for the crossing to Europe.
More than 900 have reached the Canaries since Saturday alone.
Mauritania has become the new route for those trying to smuggle themselves out of Africa since Morocco tightened its northern borders under pressure from the European Union late last year, pushing the problem further south.