A knife-wielding man shouting "Allahu Akbar" has attacked police on the Spanish-Moroccan border, injuring an officer, according to Spanish authorities. The attacker was immediately arrested by Spanish law enforcement.

The incident took place at a border post between the Moroccan town of Beni Enzar and the Spanish-controlled city of Melilla on Tuesday, local media reported.

READ MORE: ‘Viva España!’ Hundreds of migrants cross into Spanish territory from Morocco

"A man entered the border post and once inside, pulled out a large knife and confronted [police] shouting 'Allahu Akbar' [God is Great], slightly injuring a policeman," Irene Flores, a spokeswoman for the Spanish government's representative office in Melilla, told AFP.

La @policia ha detenido a un hombre que atacó con un cuchillo a los agentes en el paso fronterizo de Beni Enzar, uno de ellos herido leve. — Juan Ignacio Zoido (@zoidoJI) July 25, 2017

A spokesman for Spanish police also confirmed the incident to the news agency.

Law enforcement have opened an investigation into the case. The nationality of the attacker has not yet been determined, according to local media.

However, Reuters reported that the attacker is believed to be a Moroccan citizen, citing a source from the local government.

READ MORE: ‘Extremely violent, organized:’ 1,000 migrants storm Spanish enclave bordering Morocco (VIDEO)

Melilla, alongside Ceuta, is a Spanish enclave located on mainland Africa. The cities are common destinations for African migrants trying to reach Europe. Attempted crossings into the enclaves have resulted in injuries and even deaths.