COLOGNE, Germany — German Chancellor Angela Merkel adopted a mantra when citizens questioned her decision to open the country to refugees fleeing wars: “We’ll manage.” She kept repeating it as the lines at immigration offices circled city blocks, school gyms turned into temporary housing and the questions devolved into angry criticism.

But as Merkel campaigns for a fourth term, the German obsession with “Ordnung”— order — looks to have been assuaged. Most of the 890,000 asylum-seekers who entered Germany two years ago are in language and job training courses. Students are again playing sports in the gyms. Rejected asylum applicants are being deported.

A national election on Sunday could show how well voters think Merkel’s government managed the refugee influx.

For the chancellor and her Christian Democrats, the signs are promising. The far-right Alternative for Germany party has struggled to make immigration a major election issue. While the party is expected to win seats in parliament for the first time, the support it drew when thousands of newcomers were arriving daily has fallen along with the number of migrants trying to enter the country.

At the same time, Merkel has changed her rhetoric. Along with working to streamline and improve services for new arrivals, she now emphasizes that migrants not deserving of asylum will be sent home and that other European nations need to share the work of assisting eligible refugees.

“Merkel’s government started a highly risky maneuver with its policy of the absolute opening of the borders,” University of Heidelberg political scientist Manfred Schmidt said. “It led to a loss of control which was interpreted as a big, big problem by the people. However, the politicians realized themselves that they had a huge problem and started facing the issues.”

German opinion has been divided since large numbers of job-seeking migrants from economically depressed countries and refugees from Middle East nations wracked by civil wars and extremist groups poured into Europe in 2015.

Tens of thousands of Germans pitched in to help the refugees, bringing food and water to train stations, waving welcome signs and volunteering at shelters. Tens of thousands more took to the streets in the nationalist Pegida demonstrations, a German acronym for “Patriotic Europeans Against the Islamization of the West.”

The friction between the two sides came to a head in October 2015 in Cologne, Germany’s fourth-largest city. Henriette Reker, a mayoral candidate who oversaw municipal services for the refugees who sometimes arrived at a rate of 500 per week, was stabbed and nearly killed by a far-right extremist at a campaign event.

Reker, an independent who went on to win the election while still in a coma, concedes Germany was not prepared to take in so many desperate foreigners, yet defends Merkel’s decision to welcome refugees.

“The chancellor did the only right thing: she didn’t close the borders for purely humanitarian reasons,” Reker, 60, a career civil servant, said in an interview. “If she had closed it, and this is really not being mentioned enough, than hundreds of thousands of people would have languished.”

Two months after Reker’s stabbing, Cologne again became a flash point in the immigration debate. Hundreds of women reported being groped and sexually assaulted by migrants during the city’s New Year’s Eve celebration, causing attitudes toward young men from the Middle East and Africa in particular to harden into hostility.

The New Year’s Eve assaults marked a low point in Merkel’s popularity, they also served as a catalyst for reforms that seem to have brought the country back on track

The German parliament quickly passed a number of bills making it easier for victims of sex crimes to file complaints, enforcing the deportation of criminal foreigners and toughening asylum standards.

Merkel also benefited from an EU deal with Turkey to prevent migrants from setting out for Europe. In addition, the German government is working to slow the flow of migrants from Africa by initiating partnerships to address the conditions that cause people to leave their homelands.

Today in Cologne, most people say that while they haven’t forgotten the nearly 1 million new arrivals, their initial concerns that Germany would be overwhelmed have been allayed now that the country is running smoothly.

Not everyone was convinced, however.

“I think not everything is under control as planned,” Moritz Bertram, 20, who is from a small village northeast of Cologne, said. “Everything is overcrowded, also for the people who, of course, need the help, but don’t get it because it’s all too much.”

Reker conceded that getting people through the asylum process, out of shelters and into more permanent housing has been slow going and more needs to be done, but said progress has been steady.

Before school started in Cologne this fall, the city was able to return to local schools the last final gyms that had been serving as temporary refugee shelters.

“We’ve fulfilled all the basic requirements,” Reker said. “Now, it’s all about getting these people really integrated into our society.”