BERLIN — Chancellor Angela Merkel, who staked her legacy on welcoming hundreds of thousands of migrants into Germany, agreed on Monday to build camps for those seeking asylum and to tighten the border with Austria to save her government.

It was a spectacular turnabout for a leader who was once seen as the standard-bearer of the liberal European order but who has come under intense pressure at home over her migration policy.

Ms. Merkel will limp on as chancellor as a result of her move, an agreement with conservatives in her coalition government. For how long is unclear as populism and nationalism are taking root — fast — in the mainstream of German politics.

Despite the claims of far-right leaders, the number of undocumented migrants arriving each year is back to pre-crisis levels — and has been for some time.

… The move came after a clash over migration between Ms. Merkel and her own interior minister, Horst Seehofer, and almost toppled the coalition government she leads. …

But since she welcomed more than a million often undocumented migrants to Germany in 2015 and 2016, nationalism and populism have made a comeback in a country that has long tried to escape the shadows of its past. Migration has become the topic that will most define her legacy, and it has become a test for German democracy itself. …

Mr. Seehofer, who was the premier of Bavaria when his state became the main gateway into Germany for migrants in 2015, said he wanted Germany to block migrants at the border if they had no papers, or had already registered in another European country.

Ms. Merkel, who had insisted on free movement across borders, wanted a coordinated solution with neighboring governments. A hard border would almost certainly result in other countries re-erecting checkpoints, too.

Under the Monday agreement, migrants would be checked at the border and those who have sought asylum in another European country would be turned away. Details of exactly how this would work are still unclear.

That’s basically what Orban of Hungary was asking for in 2015, but of course he was a complete Nazi for wanting to follow EU rules instead of the German Chancellor’s whim.

By the way, isn’t it about time to have a name for what Ms. Merkel did in 2015? That’s clearly turning out to be the most crucial event of this decade.

The reason it has been so important is because it revealed what a few of us had long predicted — that the elite spirit of the age was pushing toward the assumption that established nations don’t have the to their territory, that elites ought to give away their countries to anybody who shows up.

And then Ms. Merkel, perhaps the most experienced centrist, went ahead and did exactly what I had feared.