BRUSSELS — A man opened fire Monday on a tram in the Dutch city of Utrecht, killing three people and injuring five in a shooting that authorities said may have been motivated by terrorism.

After an hourslong manhunt around Utrecht, police arrested a 37-year-old Turkish-born man, Gokmen Tanis, who they said was the main suspect. They also took into custody another person they said was connected to the attack, although they offered no further details.

“Today an attack took place in Utrecht, literally in the heart of our country,” Dutch Prime Minister Mark Rutte said at a news conference after the arrest. “We will not succumb to these terrible events.” He said that authorities still consider terrorism a possible motive but that they are also still trying to understand what happened.

Tanis was known to authorities, said Dutch Justice Minister Ferdinand Grapperhaus, standing alongside Rutte. He declined to elaborate, citing the need for an unbiased investigation.

Police spent hours searching for Tanis, releasing a surveillance photo from what appeared to be the tram taken minutes before the attack unfolded — an unusual step in a privacy-conscious country that underscored the concern sparked by the incident.

The mayor of Utrecht, Jan van Zanen, in releasing details of the deaths, said three of the injured had been seriously hurt.

“We cannot exclude — in fact, we assume —a terrorist motive,” he said in a video released on Twitter. Police spokesmen told local news outlets that domestic violence was also possibility.

Photographs from the scene of the incident, which authorities said occurred about 10:45 a.m., showed at least one body covered in a white sheet next to the halted tram near the 24 Oktoberplein, a busy intersection in southwest Utrecht.

The shooting, coming three days after an attack on mosques in New Zealand killed 50 people and left 40 injured, set off alarms in Europe.

The attack appeared to cause some confusion among Dutch authorities scrambling to respond to a burst of violence in a turbulent period. Officials said at first that nine people were injured, then revised the number downward; they also offered contradictory statements about whether there were multiple shooting sites before agreeing there was only one.

Witness accounts of the attack were somewhat contradictory, with at least one witness saying that a woman on the tram appeared to have been targeted. Others told local media that an attacker sprayed fire more indiscriminately.

One witness quoted by the NRC newspaper said a man got up inside the tram and started shooting with a “big pistol.”

“He shot around him, but seemed to be aiming at people sitting on the benches. Everybody ducked away,” said the witness, who NRC said spoke on the condition of anonymity.

Another witness said the attacker was shooting at one woman and then targeted people who tried to help her.

“We heard pop-pop-pop sounds, as though there was a silencer,” the witness, who was identified only as Niels, told the Algemeen Dagblad newspaper. “I felt that he was focusing specifically on someone, because I saw a woman crawling away. Bystanders tried to pull her out, but when they did, the man went after her specially and aimed at the bystanders.”

Authorities also increased security across the country. In Rotterdam, police said they were boosting security at mosques and at train stations. In the Dutch seat of government, The Hague, the military police who patrol government buildings carried their rifles at the ready, a different posture than normal, according to Dutch media. The threat level was lowered Monday evening.

The attack came shortly before provincial elections scheduled for Wednesday. Rutte’s center-right People’s Party for Freedom and Democracy and most major parties suspended campaigning after the attack. A far-right, anti-immigration party that is poised to do well in the elections, Forum for Democracy, said it would keep campaigning.

All mosques in Utrecht were closed after the incident, according to a spokesman for the Ulu Mosque, Utrecht’s biggest, who was quoted by the ANP news agency.