Refugees who come to Germany after entering the European Union through Spain can be turned back at the border under the terms of an agreement between Berlin and Madrid, the German Interior Ministry said Wednesday.

The agreement, which was signed Monday and will take effect Saturday, is the first of its kind since June, when an argument over border controls threatened to bring down the government of Chancellor Angela Merkel of Germany.

The rule, which will allow Germany to turn away refugees arriving along that increasingly important migration route, is a sign of how the country’s politics have shifted since 2015, when Merkel welcomed more than 1 million people.

The chancellor won verbal agreement for such deals from Greece, Italy, and Spain at a Brussels meeting in June, after her interior minister, Horst Seehofer, threatened to establish a hard border between Germany and Austria to halt migrants.