By Katya Adler
BBC News, Tarifa
Spain is processing work papers for about 700,000 illegal immigrants already living in the country after holding a three-month amnesty.
Illegal immigrants arriving in Spain will now be sent home
Other European nations, such as Italy, have called amnesties like this in the past but never on such a large scale.
And Spain's move comes at a time when the EU-wide trend is to crack down on economic migrants.
Spain was royally rapped on the knuckles for its unilateral action at a recent meeting of the interior ministers of the G5 - Europe's five wealthiest nations.
But Interior Minister Jose Antonio Alonso was on the defensive.
"Spain is a sovereign country," he said. "As such, it is respected throughout Europe. Decisions taken by the Spanish government are good for Spain and for Europe."
So why has the Spanish government taken this decision to - as its critics see it - reward illegal immigrants by giving them Spanish residency papers and work permits?
Over the last couple of decades Spain has gone from being a country of economic migrants to being a desirable destination for economic immigrants.
Immigration to Spain has increased five-fold since 1999, but the country's Socialist government says it is determined to turn what might seem like a huge problem into a distinct advantage.
Following a trend familiar throughout the EU, as Spain has become wealthier, its birth-rate has dropped and its citizens have become less keen to do what are increasingly regarded as menial jobs.
Africans and Latin Americans make up the backbone of the workforce in agriculture, construction and domestic help nowadays.
Secretary of State for Immigration Marta Rodriguez-Tarduchy says Spain needs immigrant labour and it makes sense to give work papers to the immigrants already living and working in Spain, even if illegally.
"These people were working in our shadow economy. They were using social services but not paying any taxes, so we gave them the chance over a limited period to get their papers in order without being penalised," she said.
The Spanish government presents this as a win-win situation. It gets a boost to its social security contributions of up to 1.5bn euros (£1bn) and the regularised immigrants get to breathe a huge sigh of relief.
"I feel as free as a bird now," says Malika al-Hadidi, a 42-year-old Moroccan, who for years worked illegally as a cleaner in Algeciras in southern Spain.
"Getting my papers in order was the best thing that ever happened to me. For one thing it means I can finally visit my family in Morocco. Before I had my papers I was afraid to leave Spain because I wouldn't have been able to come back."
A bit further along the southern coast, at an avocado farm in Velez Malaga, the workers are pruning and collecting the dead branches off the trees.
There is not a native Spaniard amongst them. These men are Ecuadoreans, Colombians and Moroccans, all with their residency and their work permits in order.
Mohammed Abibo was eager to praise the amnesty.
Some do not make the journey to Spain's European shores
"I arrived here a few years ago on a boat of illegal immigrants from Morocco. It was hard. We were always afraid of the police. Now it's great, just great. I feel like a proper European citizen."
The boatloads of illegal immigrants who wash up on Spain's southern shores are the most visible sign of a persistent phenomenon.
Sgt Miguel Marin is a member of the civil guard in Tarifa. This is Spain's southernmost point, where on a clear day, you feel you can almost reach out and touch Africa.
The civil guard has been equipped with the latest technology to try to catch illegal immigrants before they reach the shore, yet they still arrive in their thousands.
"It's hardly surprising though, is it?" says Sgt Marin, squinting out to sea.
"North Africa is just 14km away from this beach. There are loads of people over there who think life is better and easier here in Europe. Of course they're just going to keep coming over.
"Our job is basically to apprehend them and guide them safely to shore. It's a treacherous journey, even if it's a short one. Countless people die making the crossing every year. You have to be desperate to give it a go."
The heart-breaking images of pregnant women with hypothermia and boats filled with exhausted faces appear regularly on Spanish TV news bulletins but these days most illegal immigrants slip into Spain through its airports. They enter the European Union legally on short term work or holiday visas and then never leave.
The main conservative opposition party, the Popular Party, says the illegal immigration amnesty will just exacerbate the problem, acting, it says, as a magnet, encouraging the arrival of even more illegal immigrants in the hope that - one day - another amnesty will be called.
"The Spanish government is making the right steps to provoke a wave of xenophobia and racism which this country never had before," said Popular Party MP Gustavo de Aristegui.
"The government simply did not do its homework.
"Our European neighbours are now worried that legalised illegal immigrants will use their new papers, procured in Spain, to enter wealthier EU nations and then never leave."
But the Spanish government insists its amnesty has been a total success and that it has not gone soft on illegal immigration. It says that now the amnesty period is over, it will crack down hard on Spain's shadow economy.
But that message has yet to filter through to the hopeful economic migrants. In late April, as the amnesty drew to a close, hundreds of illegal immigrants were apprehended on the French/Spanish border.
Most of those detained by police were originally from Pakistan and India but, they said, they had come from France, Germany and even Italy in the hope of obtaining Spanish residence permits so they could remain in Europe.