Merkel and the days of terror
The decision to accept more than a million refugees was Angela Merkel's biggest political gamble.
At first, she was widely applauded for her moral courage and leadership.
She told the German people: "We can handle this," and there was a certain pride in German hospitality, in seeing citizens chant at Frankfurt railway station: "Say it loud, and say it clear, 'Refugees are welcome here.'"
For the German chancellor, the refugee crisis underlined that "the heart and soul of Europe is tolerance".
Doubts about her policy surfaced earlier this year, particularly after young women in Cologne were allegedly assaulted by groups of largely foreign men on New Year's Eve.
The alleged assaults strengthened anti-immigrant protests, but they have subsided as the numbers of new arrivals dwindled.
But the misgivings have surfaced again after four attacks in the space of a week.
Three of them were carried out by asylum seekers.
The attacks were not related and do not reflect any co-ordinated plot against Germany.
Two of them, including the attack at a wine bar in Ansbach, had a link to the so-called Islamic State. A video found by the police vowed that Germany's people "won't be able to sleep peacefully anymore".
Earlier in the year, Angela Merkel had seen her poll ratings slide - but compared with most other leaders, they remained remarkably strong.
After the incidents in Cologne, she did lose support - but more recently, after the UK vote to leave the European Union and the attempted coup in Turkey, her ratings soared.
Voters still see her as an anchor, a rock in a dangerously unstable world.
However, these latest attacks fuel concerns as to whether Germany is coping with the numbers it has had to process.
Mohammad Daleel, the Syrian refugee who killed himself and injured others in Ansbach, should have been deported months ago.
There are many others who have been refused permission to stay but still remain in the country.
- Germany attacks: What is going on?
- Ansbach attacker: Asylum seeker to IS suicide bomber
- Munich shootings: What we know
It was apparent in Munich at the weekend that many people feel insecure.
Several residents said that they had been expecting attacks.
They spoke openly about their fears.
"People in Germany are scared," said Rainer Wendt, the chairman of the German Police Federation.
Yet there was a calmness, an unwillingness to turn a tragedy into a wider denunciation of foreigners or a demand for a state of emergency.
The anti-immigration party Alternative fuer Deutschland (AfD) said under "the current ideology of dangerous 'multiculturalism', the country's domestic security and the order of Germany keeps getting destroyed".
But AfD has recently fallen back in the polls and is struggling to lift its ratings above 12-13%.
Yet these recent attacks will once again put immigration policy under scrutiny.
"It is right to debate about who the people are who come here," said Mr Wendt. There will be pressure to vet newcomers more closely.
Refugees will be a major issue when Germany goes to the polls next year, when Angela Merkel is likely to stand for a fourth term.
She is hugely dependent on Turkey and its increasingly authoritarian leader preventing further refugees crossing into Greece and the EU.
The strategy of the German government is to reassure, to refuse to adopt dramatic measures when the four attacks are not linked in any way.
Among the 1.2 million refugees who have entered Germany, there have been 59 investigations into links with terrorism.
Interior Minister Thomas de Maiziere said: "We think that we should not change our behaviour.
"We need to be more vigilant, but we cannot live in fear."
There are, however, deeper concerns about integration.
There have been programmes to teach refugees about the values of their new country, including equality between men and women, and about freedom of opinion.
The degree to which refugees integrate into Germany will, in the long term, determine whether Angela Merkel's open-door policy has worked.
Further attacks - particularly if they are linked to recently arrived refugees - will make her vulnerable at next year's elections.
With the UK bent on leaving the EU and the French president deeply unpopular, the German chancellor, more than ever, is "Frau Europe".
She remains a steady, unemotional leader who said recently: "Fear has never been a good adviser, neither in our personal lives nor in our society."