But it wasn’t long until Ms. Merkel’s Willkommenskultur was replaced by a culture of deportation, thanks in part to the threat of the far right. In 2015, Alternative for Germany turned from a predominantly anti-European Union stance to an anti-immigration one. That September it reached a high of 16 percent support in a survey.

In December 2015, the chancellor announced that the government would “drastically decrease the number of people coming to us.” Ever the champion of realpolitik navigation, Ms. Merkel kept her promise. In 2016, only 280,000 people sought asylum, a decline directly related to policies introduced by Ms. Merkel’s coalition government, including a temporary ban on family reunification, cuts in cash benefits and the repatriation of asylum seekers, even to Afghanistan.

In March 2016, Germany facilitated a deal with Turkey to stem the flow of refugees arriving in Europe that was widely condemned by human rights groups. In the coming parliamentary term, Ms. Merkel’s party hopes to designate Algeria, Morocco and Tunisia as “safe countries of origin” to which refugees can be legally returned. The center-left Social Democratic Party has supported these policies, which are also prominently backed by Alternative for Germany.

Major German parties have leaned so far to the right ahead of this election that Alternative for Germany politicians have even criticized their opponents for copying them. When the Social Democrats presented their new platform in May, it included better protection of the European Union’s external borders, faster deportations of criminal foreigners and more police. Alexander Gauland, an Alternative for Germany candidate, complained that the Social Democrats were “stealing” his party’s positions “to distract from their own failure and to win over voters.”

It was not an Alternative for Germany politician but Christian Lindner, the leader of the pro-corporate, neoliberal Free Democratic Party, who this month gave an interview to the tabloid Bild that ran under the headline “All Refugees Must Go Back!” Syrian asylum seekers should have to leave Germany as soon as their home country is safe, Mr. Lindner said, and “there is no human right to choose your location on the globe.”

Even the left-wing parties have been infected.

The Green Party, long famous for its aversion to the police, is now calling for an increase in the number of officers. Winfried Kretschmann, the Green’s first premier of a federal state, advocates “faster deportations.” In May, another Green hard-liner, Boris Palmer, the mayor of Tübingen, posted on Facebook a picture of people identified as refugees who had been caught fare-dodging with the caption “Train rides have changed in the last few years.” Mr. Palmer recently published a book titled “We Can’t Help Everyone.” Both Mr. Palmer’s and Mr. Kretschmann’s positions are controversial within the Green Party, and yet they remain important figures.

Among the six main parties, Die Linke has upheld the most tolerant refugee policies. The party says it wants deportations to decline and seeks a “right to stay for everyone.” But its rhetoric hasn’t always been so tolerant. In 2016, Sahra Wagenknecht, Die Linke’s leader, declared that “not all the impoverished and poor of the world can come to us.” She also blamed Ms. Merkel for the terrorist attack at a Christmas market in Berlin last year, citing “uncontrolled border opening.”