By Jens Hack

MUNICH (Reuters) - A young Afghan who attacked passengers on a train in Bavaria with an ax had entered Germany last summer with a wave of migrants, officials said on Tuesday, raising more questions about Chancellor Angela Merkel's open-door refugee policy.

The 17-year-old, who a witness said shouted "Allahu Akbar" (God is Great) during the attack, severely wounded four Hong Kong residents on the train late on Monday, then injured a local woman after fleeing, before police shot him dead.

The case is likely to deepen worries about so-called "lone wolf" attacks in Europe and could put political pressure on Merkel, who has welcomed hundreds of thousands of migrants to Germany over the past year.

The attacker came to Germany as an unaccompanied minor and was registered as a refugee on June 30 last year in Passau, officials said. Germany welcomed about 1 million migrants in 2015, many fleeing war in Afghanistan, Syria and Iraq.

"In the minds of many people, his arrival is directly linked to Merkel and her liberal refugee policies," said Frank Decker, political scientist at Bonn University.

The attack took place days after a Tunisian delivery man plowed a truck into crowds of Bastille Day revelers in the southern French city of Nice, killing 84. Islamic State has also claimed responsibility for that incident.

Public support for Merkel has risen since Britain voted on June 23 to leave the European Union, helping reverse a fall in her popularity caused by the refugee crisis. Decker said a Nice-style attack here could quickly end those gains.

"It would boost those who have called Merkel's policies a mistake," he said. "Merkel would be blamed."

Unlike neighbors France and Belgium, Germany has not been the victim of a major attack by Islamic militants in recent years, although security officials say they have thwarted a large number of plots.

A leader of the anti-immigrant Alternative for Germany (AfD) said Merkel and her supporters were to blame for the dangerous security situation because their "welcoming policies had brought too many young, uneducated and radical Muslim men to Germany".

Imam Arbab Ahmad, whose mosque in Wuerzburg lies about 12 kilometers (7.5 miles) from the scene of the attack, said he feared a backlash against Muslims after the attack.

"I am anxious," he said. "It was a totally inhumane attack on innocent people. Every human being should condemn it, not just Muslims."

Police found a hand-painted Islamic State flag in the refugee's room at his foster family's home, along with a letter he appeared to have written to his father, which officials said read: "And now pray for me that I can get revenge on these non-believers, pray for me that I go to heaven."

SUICIDE VIDEO

Islamic State posted a video in which a man whom it identifies as the Afghan refugee vows to carry out a suicide mission and urges other Muslims to do the same.

In the two minute and 20 second video, entitled "Germany – Video of the Islamic State Soldier Muhammad Riyad Who Carried out the Wuerzburg Attack", a young man wields a small knife, which he says he will use to slaughter infidels and avenge the deaths of men, women and children in Muslim countries.

"I will carry out a suicide operation in Germany," the young man says in the video. "I will slaughter you in your houses."

German officials were checking if the man in the video was in fact the attacker. Merkel's chief of staff, Peter Altmaier, told ZDF television: "The security authorities expect that this video is in all likelihood authentic, and also the letter."

Authorities have not released the attacker's name publicly, because he was a minor. They have said he was not on any of the intelligence services' watch lists.

Islamic State claimed responsibility for the attack, according to its Amaq news agency. But Erik Ohlenschlager, public prosecutor in Bamberg, said there was no evidence the attacker had been in contact with Islamic State, though he said the IS flag the young man appeared to have painted suggested he had developed a sympathy for the group.

Bavarian Interior Minister Joachim Herrmann said people who knew the attacker had described him as a "quiet and balanced person who went to the mosque for important holidays, but wasn't necessarily there every week.

"He was described as a devout Muslim, but not in any way one who was a radical or fanatic," Herrmann added.

The young man started attacking his passengers with an ax and a knife around 9 p.m. local time as the train was approaching its last stop, the Bavarian city of Wuerzburg, Herrmann said.

Ohlenschlager said the attacker, who had learned on Saturday that a friend of his had died in Afghanistan, struck his victims with full force in the body and head, adding: "The injuries are very bad". Two victims were in a critical condition.

After a passenger pulled the train's emergency brake, the attacker fled and struck in the face a woman who was walking her dog. He was pursued by a police unit who shot him dead.

(Additional reporting by Michael Nienaber, Noah Barkin, Andrea Shalal, Caroline Copley, Michelle Martin, Joseph Nasr and Gernot Heller, and Reuters TV; Writing by Andrea Shalal and Paul Carrel; Editing by Angus MacSwan, Larry King)