Police detained a 24-year-old Moroccan man in the village of Zumarraga in the northern Basque Country while he was on work leave from Martutene prison in the coastal city of San Sebastian, it said in a statement. A 32-year-old Spanish national was arrested in the jail.
The ministry said the two men were serving jail terms for common crimes.
The authorities launched the operation after one of the suspects published on social networks a video showing him burning his passport as jihadists are known to do in Syria and Iraq.
The two men held meetings with youths from north Africa from outside the prison in the village of Renteria near San Sebastian where they showed video recordings of Islamic State "attacks, executions and decapitations" and praised the group's actions, the statement said.
The arrests come three weeks after a wave of simultaneous shootings and suicide bombings in Paris in which 130 people were killed that were claimed by the Islamic State group.
Spain has arrested about 100 suspected Islamic extremists so far this year.