By the end of August, the Mallersdorfer Sisters had departed. In September, the first of the Syrians arrived.

In the past five years, as the number of people displaced worldwide by conflict and persecution has reached a level not seen since the end of World War II, many Germans have expressed pride that their nation — which unleashed the violence that prompted the earlier mass flight — has now become a beacon of safety and opportunity for imperiled and dispossessed people around the world. The degree to which many Germans embraced this new identity became exceedingly clear last summer, when Hungary tried to stop the mass of Germany-bound migrants traveling through the country by cutting off their access to trains. Migrants stranded outside Budapest’s Keleti train station chanted: “Germany! Germany!” And within days, roughly a thousand of them had set out on foot from Hungary and across Austria to Germany, some of them holding posters of the German chancellor, Angela Merkel. Merkel, fearing chaos should she turn the migrants away, instead sent German trains to pick them up, a decision she later called a “humanitarian imperative.” As migrants arrived at Munich’s central station, local residents greeted them with cheers and applause. Some handed out chocolate and balloons. Germans spoke of their strong Willkommenskultur, or “Welcome Culture,” and German politicians portrayed the warm reception as a moral achievement, a further step toward redefining modern Germany as a benevolent nation that has moved beyond the ignominy of its ultranationalist past.

The rise of Willkommenskultur was especially striking because Germany, like other European countries, has not traditionally viewed itself as a destination for migrants. Until the turn of the millennium, national policies on immigration could be summed up by a mantra often repeated by Chancellor Helmut Kohl, Merkel’s predecessor and mentor, that Germany is “not an immigration country.” This was despite the earlier arrival of hundreds of thousands of “guest workers,” laborers from Southern Europe and Turkey, who came to work in West German factories during the postwar economic boom. The change in attitude has been rapid; in 2012, Germany, with its strong economy, became the second-largest immigration country in the Organization for Economic Cooperation and Development, after the United States. The scale of the influx last year — roughly one million asylum seekers in all, nearly half of whom made formal applications — was exceeded in German history only by the influx of “ethnic Germans” who were expelled from Eastern Europe and the Soviet Union after World War II. The country now faces the greatest test yet of its willingness to transform itself into a multiethnic nation.

The migrant influx has also put widely held convictions about European values to the test. Some countries have instituted border controls to manage or repel the movement of migrants, undermining one of the European Union’s fundamental pillars: free travel across open internal borders. The influx has also increased the popularity of far-right, anti-immigration parties, and even centrist politicians now often see an anti-immigration stance as a necessary act of political survival. In January, Denmark, whose minority government is dependent on cooperation with the far-right Danish People’s Party, passed a law enabling authorities to seize jewelry and cash from asylum seekers in order to offset the costs of their stay. In Austria, an initial welcome of asylum seekers dissipated after far-right parties made decisive gains in regional elections last fall. In February, Austria led a coordinated effort with countries to its south to shut down the migration route through the Balkans. The move trapped tens of thousands of asylum seekers in Greece, a nation with a woeful incapacity to care for them. Many have been stranded in squalid, makeshift camps.

Merkel, concluding that the only way to hold the European Union together was to curb migration closer to the source, pushed for a deal with Turkey. Turkey — in exchange for, among other incentives, the revival of stalled talks on its bid to join the European Union — agreed in March to take back Syrians and other migrants who used the country as a steppingstone to Europe. The deal, questionable in legal and ethical terms, did little to quell the concerns of many Germans about the migrants already among them. Terrorist attacks in Paris and Brussels have inflamed fears that ISIS is exploiting the refugee crisis to infiltrate Europe undetected; they have also heightened longstanding concerns about Islamist radicalization in disaffected migrant communities. In February, the head of Germany’s domestic intelligence service assessed the risk of a terrorist attack in Germany as “high.” And the wave of sexual assaults and robberies attributed to a multitude of young North African and Middle Eastern men, among them asylum seekers, on New Year’s Eve in Cologne drew comparisons to the mass sexual assaults on women in Tahrir Square during the Egyptian revolution, sparking a debate about a clash with “Muslim culture,” as one conservative parliamentarian put it.

Through it all, Germany continues to struggle with the challenge of transforming itself into a republic of shared ideals rather than shared blood. Across the mainstream political spectrum, there is a growing sense that German values must, in the face of rapid social change, be quantified and propagated. What exactly those values are, however, is far from settled. German political discussion on the matter often revolves around the concept of leitkultur — or “leading culture” — common values that extend beyond mere adherence to the law. Conservative leaders often describe those values as Judeo-Christian and suggest that those from other “cultural circles” stay out or adapt. Some German leftists counter that a formerly Nazi country should not compel anyone to abide by a perceived set of common values. Amid the debate, efforts to relay German cultural values to newcomers can become muddled. A guide to “Germany and its people” published by the Bavarian public broadcaster tells migrants to “always look the person you’re talking to in the eyes.”

As Germany struggles with these questions of identity, fear is fueling the kind of far-right, populist backlash that, until recently, was contained by a mindfulness of the Nazi past. The migrant influx has been accompanied by a sharp rise in extremist demonstrations and violence directed at foreigners. It has also provided a boon to Alternative for Germany, a far-right party that formed in 2013 in opposition to the euro and that has now galvanized support by vowing to keep migrants out. Supporters at party rallies often chant: “Wir sind das Volk,” or “We are the people,” a refrain previously employed by pro-democracy demonstrators in communist East Germany, when the phrase evoked a yearning for democratic rights. Now it has been co-opted by far-right groups who perceive the “we” as having a tribal or ethnic meaning. In January, Alternative for Germany’s leader, Frauke Petry, suggested that the German police “make use of firearms” if necessary to keep migrants from crossing the border. After the attack in Brussels, she declared: “The dream of a colorful Europe is broken, bombed away yet again. Accept it at last.”