The German government has agreed with Madrid that it can send back to Spain migrants who have already applied for asylum there, a spokeswoman for the interior ministry said on Wednesday, in what is the first deal of its kind.
The move comes after a dispute between Chancellor Angela Merkel's conservatives and their Bavarian allies over returning migrants that nearly split them and brought down the government.
Interior Ministry spokeswoman Eleonore Petermann said the two EU countries had signed the deal on Monday that would, from Saturday, enable them to send such migrants back to Spain within 48 hours. Spain did not require anything in return, she added.
A Spanish government spokeswoman said the deal was part of the agreements reached in the last European summit on migration in late June. She said Spain accepted Germany's demand to send back asylum seekers who got to Germany from Spain.
Spain has become the new main entry point for asylum-seekers fleeing Africa. Around 19,000 asylum-seekers arrived in the first five months of this year, almost as many as in all of 2017, eclipsing for the first time the numbers flowing through north Africa to Italy.
More than 1.6 million migrants have arrived in Germany since mid-2014, provoking tensions and propelling the far-right Alternative for Germany (AfD) into the national parliament.
German Interior Minister Horst Seehofer, leader of Christian Social Union (CSU) - the Bavarian sister party to Merkel's Christian Democrats (CDU) - is keen to show he is taking action to reduce immigration as his party faces a tough October regional election in which the AfD is expected to fare well.
Germany is seeking similar deals with Italy and Greece. The discussions with those countries are still going on, Petermann said, adding that both Italy and Greece had made counterdemands.
Merkel is due to meet Spanish Prime Minister Pedro Sanchez at the weekend and migration will feature in their talks, a spokeswoman for the German government said.
Sanchez pushed migration up the agenda shortly after he took office in June by accepting the Aquarius, an NGO boat carrying 629 migrants that was blocked from docking in Italy and Malta, and says Spain is committed to a joint European response to illegal migration.
Until now it has only been possible to reject migrants at the border if they enter Germany via a safe neighbouring country without the necessary documents to enter and do not want to apply for asylum here.
But those who wanted to apply for asylum in Germany could enter up until now even if they had already applied in another country.