OCHSENFURT, Germany -- By all accounts, the 17-year-old Afghan behind an ax-and-knife rampage aboard a commuter train in Germany seemed to be quickly integrating and adapting to life in Germany - until something, possibly the death of a friend back home, prompted him to radicalize and turn on the country that took him in.
Five people were wounded in the attack late Monday near Wuerzburg, including four members of a Hong Kong family who were on the train and a woman walking her dog outside. Two remained in critical condition Wednesday, and Interior Minister Thomas de Maiziere said it wasn't clear if they will survive.
The attacker, whose name hasn't been released by authorities, was killed by police.
The Islamic State of Iraq and Syria (ISIS) claimed responsibility for the attack and posted a video in which the teen waved a knife and referred to himself as a "soldier of the Islamic State." During the attack, witnesses said he yelled "Allahu akbar," Arabic for "God is great."
The teen was one of about 60,000 unaccompanied minors who came into Germany last year amid a flood of 1 million migrants. Authorities say such young people are particularly traumatized and in need of help, but also vulnerable to radicalization by Islamic extremists.
He wasn't on authorities' radar, and people who knew him said he seemed to be fitting in. He played soccer with the locals and had an internship at a local bakery, a growing command of the German language and a new home with a foster family outside the serene Bavarian town of Ochsenfurt.
He was a Sunni Muslim who went to mosque only on holidays, but prayed regularly at home.
"He always seemed relaxed, pleasant, he smiled, he was completely unobtrusive, in the best sense," said Simone Barrientos, 52, who lived down the road from the boy's refugee home and belongs to a group of volunteers that helps refugees in Ochsenfurt.
"I would see him around, we exchanged perhaps a couple of words," she said.
Barrientos said people who interacted with him are at a loss to explain what happened.
"With all these young people, you have to assume trauma. To do anything else would be naive," she said. "Perhaps people who have been traumatized develop different strategies, and in his case, his strategy was probably to keep things close to his chest."
German Chancellor Angela Merkel on Wednesday called the attack "unbelievably cruel" and said that "there is still a lot to learn about the attacker and the background to the crime," promising that "everything will be done to seek clarity."
Like those who knew him, authorities are struggling to determine what caused the teen to radicalize.
Two days before the attack, he found out that a friend had died in Afghanistan and reportedly was very agitated by the news, but investigators say exactly what happened is unclear.
After that, his foster parents told the police he acted differently, spending a lot of time on his cellphone, though it wasn't clear who he was speaking to.
As he left Monday, he told his foster family he was going on a bike ride. His online footprints seemed inconspicuous until shortly before the attack, authorities said. He did, however, have a hand-painted flag of the Islamic State of Iraq and Syria in his room, a senior German security official said.
"He was active on social media, had his page there, but there were no hints of any extremist Islamist thought," Bavarian criminal police investigator Lothar Koehler said. "However, 24 hours ago, he posted a cryptic message about the enemies of Islam."
In the video released by ISIS, the teen called himself a "soldier of the Islamic state" and urged other Muslims in the West to "kill these infidels in the countries that you live in."
"I have lived in your own home and have planned to behead you in your own territory," he said in his native Pashto. "I will behead you with these knives and break your necks with these axes."
Investigators found a passage among notes in the attacker's apartment that read, "Pray for me that I can take revenge on these infidels and pray for me that I will go to heaven," Koehler said.
Koehler said the teen had registered as a refugee in June 2015, when he crossed into the country from Austria. German authorities sent him to an asylum home for unaccompanied minors in Ochsenfurt near Wuerzburg, a nondescript yellow four-story building with small metal balconies, located at the end of one of the town's narrow streets.
Three police officers kept journalists from talking to other residents there on Wednesday.
The youth received asylum in March and had a residency permit.
Besides interning at the bakery and playing soccer in a local club, he attended school on a regular basis and rode around the little medieval town on a bike a volunteer had given him. There was hope that he could soon get into a job training program.
He had been living since July 1 with his foster family, whom he had been placed with because of his exemplary behavior, the head of the social welfare office in the Wuerzburg area, Michael Horlemann, told daily Die Welt.
"We now need to analyze very carefully how, despite these favorable conditions, it could still come to this act of violence," Bavarian social affairs minister Emilia Mueller said.
Following the attack, Germany's head of domestic intelligence reiterated warnings that unaccompanied refugee teens are particularly vulnerable to becoming radicalized.
"Islamists and Salafists and different Islamist groups are trying to talk to young refugees at the asylum shelter," Hans-Georg Maassen said on public ARD Television. "We must keep an eye on this group. We must make sure that nobody talks to these people, they mustn't be the target and especially not the victims of Islamist groups."
There's a risk even for those not targeted by extremists that they may radicalize because of things they see online, which is what authorities believe happened in this case.
It's not clear how the teen came to Germany, where exactly in Afghanistan he is from or where his family is now, though officials said Wednesday they had applied to come to Germany via a family reunion program.
Investigators haven't yet told the public what kind of persecution the attacker may have suffered himself in Afghanistan -- something each asylum-seeker must lay out during an interview with the federal office for asylum seekers.
Germany registered about one million migrants last year and many have been on edge about how the country will cope with them. Fears were fueled by a string of sexual assaults and robberies on New Year's Eve in Cologne that prosecutors say were committed largely by foreigners.
Though concerns have lessened as the numbers have slowed this year, the train attack has the potential to add new fuel to anti-immigrant sentiment.
But Tobias Klaus, a spokesman for Germany's Federal Association for Unaccompanied Minor Refugees, said the incident shows "we don't need less, we need more help."
"There is no absolute protection against radicalization, but we can reduce the danger by giving the minors a real chance and helping them with strong perspectives," he said.