BERLIN (AP) — An off-duty police officer and two other passengers on a regional train in Germany overpowered a Iraq-born man who wounded five people including the officer with a knife on Friday, authorities said.

A top law enforcement official said the 31-year-old attacker had been investigated for possible Islamic extremism while living in a refugee hostel in 2017, but that the motive for the train attack remained hadn’t been determined.

Four of the injured were treated in hospital for wounds to their hands or face and head, while one victim had been stabbed in the shoulder blade. None were in life-threatening condition. The attacker was also injured and taken to a clinic.

The train had just pulled out of the station at Herzogenrath near the border with the Netherlands and was heading for the western German city of Aachen at 7:42 a.m. local time when the man began attacking fellow passengers “randomly and arbitrarily,” state interior minister Herbert Reul said. He praised the courage of the 60-year-old off-duty officer and passengers who had “prevented worse harm.”

He described the attack as “a gruesome crime that was stopped in an enormous act of courage.”

The motive for the attack was under investigation. Authorities were investigating the possibility of an extremist motive but hadn’t confirmed it, Reul said. About 200 officers were deployed to secure evidence at the scene and look after the victims.

Reul said the man had undergone a police check for possible Islamic extremism after the refugee hostel where the man had been living reported that he had grown a beard, changed his behavior and isolated himself from his fellow residents. He had had no further contact with police.

He said that investigators were probing to what extent an Islamist motive might have been involved. The man’s current citizenship could not immediately be determined, he said.