It has been a bad month for Germany.

A very bad month.

Since July 18, Muslim terrorists of Afghan, Iranian and Syrian descent have carried out attacks in four German cities — Wuerzburg, Munich, Ansbach and Reutlingen — and killed 10 people and injured nearly two dozen.

Two of the attackers were Syrians who had entered Germany as migrants and had been living off social welfare benefits. They seem to have been inspired by Islamic State, the jihadist organization that has claimed responsibility for a series of deadly terrorist incidents in the Middle East and Europe since 2015.

Prior to these assaults, scores of German women were sexually molested in Cologne as Germans rang in the new year. It’s widely believed the perpetrators were Arab men.

These violent eruptions have rattled and angered many Germans, strengthened anti-immigration parties like Alternative for Germany and gravely damaged the reelection prospects of Chancellor Angela Merkel, who had claimed that the influx of newcomers would be in Germany’s interests if they could be successfully integrated.

Since last year, Germany has admitted about one million migrants from the Middle East. The vast majority are Muslims from Syria, which is embroiled in a civil war, and from Iraq, which is torn by sectarian violence and under siege by Islamic State.

Due to the sheer number of arrivals, German border police were unable to properly screen the asylum seekers, many of whom arrived without passports or official documents. Upwards of 70 percent of the migrants could not provide proper identification papers, according to Markus Kaim, a senior fellow at the German Institute for International and Security Affairs in Berlin.

When the migrants began pouring into Germany last summer, thousands of Germans greeted them hospitably. While countries such as Greece, Poland and Hungary encouraged them to move on, Germany welcomed them in an extraordinary show of generosity.

One can only speculate why the German government adopted such an open-minded policy. Holocaust guilt may well have been an important factor in its calculations. Having conceived and implemented the greatest crime in recorded history, which resulted in the deaths of six million Jews, Germany may have thought that a grand gesture was necessary after the ugly Nazi interregnum.

In the aftermath of World War II, Germany launched a comprehensive process of vergangenheitsbewaltigung, or coming-to-terms with its Nazi past. Germany channelled reparation payments to Holocaust survivors and gradually formed special bonds with the state of Israel.

But as masses of Syrians, Iraqis and Afghans poured into Europe via Turkey, Merkel — a decent and upright German — felt she had an obligation to them. So Germany decided to lend a helping hand to migrants fleeing war and seeking a more secure life for themselves and their children in a stable and prosperous country.

It was not the first time Germany had admitted Muslims to its shores. During the 1950s, 1960s and 1970s, Germany let in hundreds of thousands of Turkish guest workers and their families. Since the Turks have not been an undue burden on the country, the assumption was that a new wave of Muslim migrants could be accommodated as well.

It would appear that most Germans agreed with Merkel’s open door policy, but in the wake of the bloodshed in Germany, this thesis is under scrutiny. Merkel has tried to assure her fellow citizens that she has the situation in hand. As she put it recently, “We will resolve this and do everything possible to protect the safety and freedom of all people in Germany.”

The minister of interior, Thomas de Maiziere, has reminded Germans that only a tiny minority of migrants have had links to terrorism and that the rest are peaceful and law-abiding.

By virtue of a $6 billion agreement signed by the European Union and Turkey earlier this year, the flow of migrants from the Turkish mainland to Europe has been staunched and far fewer migrants are requesting asylum in Germany.

But Germany should brace itself for more jihadist attacks. Following last November’s murderous Islamic State rampage in Paris, which claimed the lives of 130 civilians, Germany declared war on that loathsome organization, dispatching an armada of personnel and military equipment to the Middle East — around 1,200 soldiers, six reconnaissance aircraft and a refuelling plane. By way of response, Islamic State warned Germany it was in its crosshairs.

It goes without saying that jihadist attacks against Germany have had a detrimental effect on Merkel’s political future. Although she has been regarded as a competent steward of the nation’s affairs, her popularity has plummeted and fringe parties that may well siphon votes away from her party have emerged.

The Alternative for Germany, a right-wing populist party with a dim view of Muslim immigration, has gained new followers of late and may yet cut into Merkel’s base in the next election.

Merkel’s momentous decision to open the floodgates to Muslims may have been a mistake of disastrous proportions. It could haunt her for the rest of her career.