A ministry statement said a Moroccan arrested in the central town of Aranjuez spent many hours viewing and spreading ISIS-related video material and displayed a fanaticism that fit the profile of a dangerous "lone actor" recruited to carry out attacks.
The ministry later said police had arrested another Moroccan who had traveled to Turkey recently to join ISIS in Syria but was sent back by Turkish authorities.
The statement said the man, arrested in the northern town of Irun, had been under investigation for spreading propaganda for ISIS by praising its attacks and those who traveled to fight for it.
It said he was linked to two other Moroccans arrested in northern Spain over the past year for similar offences.