Two people, including a two-year-old boy, were killed and three others injured in a stabbing attack in Bavaria, German police said.

The suspect, a former asylum-seeker who was supposed to be leaving Germany, was arrested after the attack on Wednesday.

Chancellor Olaf Scholz said that authorities must clear up why the suspect was still in the country.

Police said the incident was not a terror attack (Ralf Hettler/dpa via AP)

He said the attack, a month before a national election in which curbing irregular migration is a major issue, must have consequences.

The attack occurred just before noon in a park in Aschaffenburg, a city of about 72,000 people.

Bavaria’s top security official, Joachim Herrmann, said the assailant attacked the boy, who was part of a group of kindergarten children, with a kitchen knife.

He said the two-year-old of Moroccan origin was killed, along with a 41-year-old German man who was passing by and appeared to have intervened to protect the other children.

Bavarian officials said two adults and a two-year-old Syrian girl were injured and taken to a hospital for treatment, and none of their lives were in danger.

Other passers-by chased the suspect and he was arrested 12 minutes after the attack, Mr Herrmann said.

He said the suspect, a 28-year-old Afghan national, had come to authorities’ attention at least three times because of acts of violence.

On each occasion, he was sent for psychiatric treatment and later released.

Rescue and security workers at the scene in Aschaffenburg, Germany (Ralf Hettler/dpa via AP)

The suspect is believed to have arrived in Germany in November 2022 and applied for asylum in early 2023, Mr Herrmann said.

On December 4, he told authorities that he would leave the country voluntarily and would seek papers from the Afghan consulate.

A week later, German authorities formally closed asylum proceedings and told him to leave.

Police will work over the coming days to identify his motive, Mr Herrmann said, adding that suspicions so far point to his psychiatric illness.

A first search of his room at a refugee home found no evidence that he had radical Islamic views, and only turned up medicine that would fit with his psychiatric treatment, he said.

The attack is politically sensitive a month before Germany’s national election.

Mr Scholz issued a strongly-worded statement condemning what he called “an incomprehensible act of terror”.

“I am tired of such acts of violence happening here every few weeks — by perpetrators who came to us to find protection here,” he said.

“Mistaken tolerance is inappropriate here. Authorities must clear up at high pressure why the attacker was still in Germany at all.”

That must lead to “immediate consequences — it is not enough to talk,” Mr Scholz added. He did not elaborate.

Following a knife attack by an Afghan immigrant in Mannheim in May that left a police officer dead and four more people injured, Mr Scholz vowed that Germany would start deporting criminals from Afghanistan and Syria again.

He vowed to step up deportations of rejected asylum-seekers following a knife attack in Solingen in August in which a suspected Islamic extremist from Syria is accused of killing three people.

At the end of August, Germany deported Afghan nationals to their homeland for the first time since the Taliban returned to power in 2021.