A man arrested on Wednesday night after killing one and injuring another with a machete was illegally in Spain and facing expulsion to Morocco.

The crime, which saw the murder of a church worker and the near fatal stabbing of a priest last night, was classified as an alleged terrorist incident.

El Confidencial reported that police had already arrested Yassine Kanjaa, 25, in June last year after discovering he did not have permission to be in Spain.

Authorities had apparently started the process to return Kanjaa to his country of birth, Morocco, last year, but he remained free instead of being transferred to a Foreigner Detention Centre and expelled within a 60-day period, per the law.

It was not clear whether the delay was with the Spanish or the Moroccan authorities, who needed to recognise Kanjaa as a citizen and issue him a passport in order to return. 

Police officers detain a person following a stabbing incident at a church in Algeciras, Spain

Police officers detain a person following a stabbing incident at a church in Algeciras, Spain

Police officers detain a person following a stabbing incident at a church in Algeciras, Spain

Spanish police detain Yassine Kanjaa after the machete attacks on Wednesday night

Spanish police detain Yassine Kanjaa after the machete attacks on Wednesday night

Spanish police detain Yassine Kanjaa after the machete attacks on Wednesday night

The attack occurred last night at around 7.30pm local time (6.30pm GMT) in the port city of Algeciras in the Spanish autonomous community of Andalusia.

Kanjaa lived on Calle Ruiz Tagle, a street adjacent to the San Isidro church first attacked, and four minutes away from the church of Nuestra Senora de la Palma he raided moments later.

Kanjaa is understood to have argued with worshippers at San Isidro Roman Catholic Church before returning an hour later, around 7.30pm with a Koran in his hand, and stabbing Mr Rodriguez in the neck.

He then entered the church of Nuestra Senora de la Palma and attacked the sexton after destroying crosses and religious images.

The sexton escaped but was pursued by the attacker and sustained fatal injuries, dying on the spot.

The assailant was disarmed by police arriving on the scene and taken into custody. 

Assailant is pictured wielding a large machete, attacking a priest and a sexton in two churches

Assailant is pictured wielding a large machete, attacking a priest and a sexton in two churches

Assailant is pictured wielding a large machete, attacking a priest and a sexton in two churches 

The attacker's machete-like blade is pictured lying on the floor following the assault

The attacker's machete-like blade is pictured lying on the floor following the assault

The attacker’s machete-like blade is pictured lying on the floor following the assault

Algeciras is a coastal city on the southern tip of Spain between Cadiz to the west and Marbella to the east. 

The two churches are several hundred metres apart and located in an area very close to the port.

Police initially said several people had been wounded but later clarified it was only the priest, with the emergency services confirming he had sustained injuries ‘to the neck’.

The mayor of Algeciras said the sexton who died was called Diego Valencia and identified the priest as Antonio Rodriguez.

In a posting on Twitter, the local congregation said Rodriguez, 74, had been celebrating the Eucharist at San Isidro church when he was attacked, describing his condition as ‘serious but stable’.

Reports since say he is expected to recover. 

A police source told AFP the assailant was wearing a long robe and had ‘shouted something’ as he carried out the attack.

Local reports said he ‘proclaimed Allah’s greatness’ after his arrest. 

Eyewitnesses at Nuestra Senora de La Palma told local media that a man ran into the building at around 7:30pm just as they were finishing the Eucharist service. They said he was shouting and had started to throw icons, crosses and candles to the floor.

Prosecutors opened a terror probe which is being led by a judge from the Audiencia Nacional, Spain’s top criminal court which handles terror-related cases.

Spanish police have not yet made any official comment on the reports of the suspect’s immigration status and his expulsion order.

The attack will be investigated by Spain’s Audiencia Nacional court in Madrid.