By Noah Barkin
BERLIN (Reuters) - Near the end of a recent campaign speech in northern Germany, Chancellor Angela Merkel turned to Europe's refugee crisis of 2015 and offered her audience a comforting dual message.
Germans should be proud of the warm welcome they gave hundreds of thousands of asylum seekers, many of them fleeing war and persecution in the Middle East, she told an audience of over 1,000 gathered in the fishing village of Steinhude.
Then she shifted gears: "What happened in 2015 cannot, should not and must not happen again."
It is a phrase she has used repeatedly in market squares across Germany as she campaigns for a fourth term in a federal election on Sept. 24 that she is widely expected to win. [nL5N1LQ0H1
Two years since she opened Germany's borders to asylum seekers to avert what she says was a looming humanitarian disaster, and saw her popularity slide as a result, Merkel has climbed her way out of the deepest hole of her political career.
There are many factors behind her comeback. But few are as important as her skill at spinning a narrative about the refugee crisis that many Germans can support, whether they cheered or condemned her actions of 2015.
"Merkel is not running on a policy of open borders and that fits perfectly with the mood in the country," said Robin Alexander, author of a best-selling book on the German government's handling of the refugee crisis.
"Many people like the image of Germany as a model of humanitarian virtue. At the same time they know the country could not continue to welcome refugees like it did. It is this set of feelings that Merkel is appealing to."
By the end of 2015, 890,000 asylum seekers had entered Germany, many without proper identity checks, overwhelming local
Merkel's actions divided Europe and led to a surge in anti-immigrant sentiment. The hard-right Alternative for Germany (AfD) party seems sure to enter parliament for the first time.
A year after her decision, and following a series of small-scale attacks in Germany by Islamist militants, her popularity ratings had plunged 30 points to 45 percent and she faced questions about whether she would run for chancellor again.
Yet today, 63 percent of Germans say she is doing a good job and, according to a Bertelsmann Foundation survey this week, 59 percent believe the country is on the right track.
"It has been a long, difficult road back," said one of her top aides. "But we have gotten to a point where the refugee issue is no longer a negative for Merkel in the election campaign."
Merkel has been helped by external events such as Britain's vote for Brexit last year and Donald Trump's election victory in the 2016 U.S. presidential election, both of which reinforced her appeal as a guarantor of stability.
A decision by Macedonia in early 2016 to shut its border with Greece stemmed the flow of refugees, easing pressure on Germany. And the country has not suffered a large-scale Islamist attack, an event which might have triggered a voter backlash.
But Merkel's knack for understanding how Germans tick has also been crucial.
At many of her public appearances, she is confronted by anti-immigration protesters who try to drown out her speeches with whistles and chants of "Merkel must go!".
In Steinhude, a woman held up a sign showing Merkel's diamond-shaped hand pose over a German flag with a blood-spattered bullet hole in the middle. "I offer you terror, death and chaos", the sign read.
But the dozen or so protesters were dwarfed by supporters who applauded her message.
"I'm not sure if there was another way to handle the refugee crisis. Those refugees had to go somewhere," said Willi Kordes, 70, who runs a sewage treatment firm in nearby Vlotho. "I don't trust anyone to do it better."
Working in her favor in the election is the fact that many of Germany's other established parties, including the centre-left Social Democrats (SPD), led by her main challenger Martin Schulz, backed her open-door policy.
The AfD, running a racially-tinged campaign that has put off some voters, has come off its 2016 highs in the polls. The one mainstream party that has offered a hardline alternative, the Christian Social Union (CSU), is the Bavarian sister party to Merkel's Christian Democratic Union (CDU). A vote for the CSU is akin to a vote for Merkel.
A crucial factor behind Merkel's rebound has been the decline in asylum seekers entering Germany. About 280,000 arrived in 2016, with another drop likely this year.
Merkel takes credit for this, pointing to a deal she brokered between the European Union and Turkey, under which Ankara has cut the number of migrants crossing into Europe via its territory.
But critics say the closing of Balkan borders -- which Merkel publicly opposed -- was the real driver.
Some see parallels with her behavior in the euro zone financial crisis, when European Central Bank President Mario Draghi's pledge to do "whatever it takes" to keep the currency bloc together, allowing her to stick to a hard line towards euro states such as Greece without fear of consequences.
In the refugee crisis, it has been countries like Macedonia, Turkey and Hungary - which shut down routes the refugees used - that have done Merkel's "dirty work", allowing her to maintain the image of a caring leader who helped people fleeing war.
The approach has helped Merkel extend her control over the political centre. Some right-wing voters may have fled for the AfD but polls suggest young, urban voters who traditionally lean left could fill the gap.
Germany's economy has been strong enough to absorb the influx of refugees without big cracks emerging in society. In reaction to its Nazi past, Germany has emerged as a more open, tolerant country than many assumed when the crisis hit.
A survey published this month ranking the top fears of the Germans put terrorism at the top. But a separate poll for the Bild newspaper showed they do not see curbing immigration as a priority.
"Germans are astonishingly global, liberal and open to the world," said Menno Smid, head of the Infas Institute for Applied Social Sciences, which released a survey last month showing broad acceptance of refugees in Germany. "We are the winners from globalization. The economic factors that led to Trump simply don't exist."
(Editing by Timothy Heritage)