No one was injured in the attack which happened in the early hours of Monday, a spokesman for the Spanish central government's representative in Ceuta said.
“Three bullets struck a mosque early this morning,” he told AFP, adding police were looking for two masked gunmen on a motorcycle.
A handful of worshippers were inside the Muley el Mehdi mosque, one of the most important in the tiny territory, at the time of the shooting, according to local media.
Ceuta and another Spanish enclave, Melilla, sit on Morocco's Mediterranean coast, and are each surrounded on three sides by Morocco.
They both have a significant Muslim population. Around 37,000 of Ceuta's 85,000 residents are Muslim, according to the Union of Islamic communities of Spain.