Spain and Senegal have agreed a series of measures to curb illegal migration to the Canary Islands.
Some 4,000 Senegalese have been repatriated this year
Spanish PM Jose Luis Rodriguez Zapatero said that over the next two years, 4,000 Senegalese would be allowed to work temporarily in Spain.
Mr Zapatero was in Senegalese capital, Dakar, for a day of talks.
Spain's Canary Islands are a tempting destination for many Africans, and at least half of almost 30,000 illegal arrivals in 2006 have been Senegalese.
Spain repatriated 4,000 of them recently after an agreement with the West African nation.
After signing the accords with Senegalese President Abdoulaye Wade, Mr Zapatero said: "This makes possible the emigration of Senegalese under a legal framework through our labour ministry and the job market. Happily, we are in need of labourers."
Mr Zapatero said Spain would keep its promise, made earlier in the year, to give 20m euros ($26.6m) to Senegal to fund job training and create economic opportunities for youth.
"Nothing is worse for a country than losing its human capital," he said.
Both countries have also agreed to extend till June a border patrol operation to deter potential migrants.
The joint operation was due to expire at the end of December.
Tens of thousands of Senegalese, seeking to escape poverty and unemployment, have tried to make the dangerous journey to the Canary Islands over the years.
Many have died at sea, and joint patrols have been sent up to try to prevent illegal immigrants reaching Europe.
In Senegal, jobs are scarce and the average income is less than $2 (£1) a day compared to about $70 (£35) a day in Spain.
In the past, President Wade has been criticised by many in the country for allowing the repatriation of Senegalese from Spain.
Critics say this blocks a migrant's only chance at a better life when jobs are scarce at home.
The president is seeking re-election in February, and correspondents say that with unemployment a major problem, the promise of job opportunities in Spain will do his campaign no harm.
But Spain will only be able to offer contracts to a fraction of those looking for work, so gaining a visa will still be a lottery and illegal journeys by land and sea will not be ended, they say.
Mauritania: 4 former Guardia Civil patrol boats, 1 Guardia Civil patrol boat, 1 Guardia Civil helicopter, 1 Customs patrol
Senegal: 1 Italian ship, 1 Italian plane, 1 Guardia Civil patrol boat, 1 Spanish Police helicopter, 3 Senegalese boats, 1 Senegalese plane, 1 Finnish plane due
Cape Verde: 1 Portuguese frigate