The primary suspect in the shooting aboard a Dutch tram that left three people dead and five wounded confessed on Friday to the attack, and said that he acted alone, prosecutors said.

The public prosecutor’s office has said that it intends to bring terrorism charges against the suspect, Gokmen Tanis, in the attack Monday morning in the city of Utrecht, the Netherlands, but it is also investigating whether he had other motives.

Mr. Tanis confessed in a closed court hearing on Friday, the office said — his first appearance in court since he was arrested hours after the shooting. The judge ordered him held for 14 days, the maximum allowed in an initial hearing, but pretrial detention can be extended up to 90 days.

“The 37-year-old suspect admitted to a judge the criminal facts he was suspected of. He also testified that he acted alone,” prosecutors said in a statement. “It is in the best interest of the investigation not to say anything further about his testimony.”