MADRID - Spanish authorities said they were investigating what they called a possible "terrorist" incident after a machete-wielding man attacked several people at two churches in the southern port city of Algeciras, killing at least one person.

The man attacked clergymen at two different churches - San Isidro and Nuestra Senora de La Palma, around 300 metres (1,000 feet) apart - just after 8pm on Wednesday evening in downtown Algeciras, a spokesperson for the city said. A source at Madrid's High Court said the incident was being investigated as terrorism.

Police said the attacker had been arrested, and a police source shared footage showing two officers escorting a man in a hooded sports top in handcuffs through a police station. Police have not released details of his name or nationality. Local media, including El Pais newspaper, said he was a 25-year-old Moroccan.

The man who was killed was Diego Valencia, a sacristan at the Nuestra Senora de La Palma church, while the titular priest of the parish church of San Isidro, Antonio Rodriguez, was among the injured and is in serious condition, the Algeciras city spokesperson said.

An unknown number of others were also injured. El Mundo newspaper reported that four people were hurt in the attack.

Police said the suspect first entered the San Isidro church and attacked Rodriguez. A statement by the Algeciras Salesians said Rodriguez, 74, had been celebrating Eucharist when he was attacked.

The assailant then went into the Nuestra Senora de La Palma church where he damaged property before attacking Valencia, who fled the church but was chased by the suspect, who inflicted further, fatal injuries on him outside, police said in a statement.

The parish priest at Nuestra Senora de La Palma, Juan Jose Marina, told broadcaster SER the suspect went straight for Valencia after the mass had finished, suggesting he might have believed Valencia was the priest.

"Possibly, this death was meant for me and it found him instead," said a tearful Marina.

Spanish Prime Minister Pedro Sanchez expressed his condolences to the victims of the "terrible attack" on his Twitter account, while the secretary general of Spain's Episcopal Conference, Francisco Garcia, spoke of his "great pain" on hearing the news.

"These are sad times of suffering, we are united by the pain of the victims' families and for the Cadiz Diocese," he said on Twitter.

Jose Ignacio Landaluce, the mayor of Algeciras, has declared a day of mourning in the city for Thursday and a rally outside Nuestra Senora de La Palma church at midday.

Earlier on Wednesday, two people were killed and several others injured when a 33-year-old stateless Palestinian man attacked them with a knife on a regional train travelling between Kiel and Hamburg in northern Germany, authorities said.

(Reporting by David Latona, Belén Carreño and Aislinn Laing; Editing by Rosalba O'Brien)