Officers arrested Mohammed El Bali, who was "in charge of a jihadist cell based in Nador", a nearby town in neighbouring Morocco, a short statement from the Spanish interior ministry said.
He was arrested under an international warrant issued by Morocco.
The ministry said it would issue further details later.
Melilla, home to around 80,000 people, has one of the European Union's two land borders with Africa, along with another Spanish territory, Ceuta to the west.
In June Spanish security forces broke up an Al-Qaeda-linked network operating in Ceuta and the neighbouring Moroccan town of Fnideq, arresting eight people.
That network was suspected of sending dozens of Islamist militants — some minors — to Syria, in some cases to carry out suicide attacks, the ministry said at the time.