The two were detained in Madrid and Roda de Ter in the northeastern region of Catalonia, and the interior ministry said they had joined the group voluntarily "and acted as individual terrorist cells, decentralised and pre-activated for the commission of terrorist acts in Spain."
They were "focused on recruiting young Muslims with the ultimate aim of forming an 'army of followers' invisible to police control," it added. A police spokesman, however, was not able to say whether they had actually recruited anyone.
They also "did work of propaganda and extolling of Daesh's military victories and gains, all of which was presented in an attractive visual format to gain the largest possible amount of followers," the ministry said, using an Arabic acronym for IS.
According to police, they were quickly radicalised, to the point that "they offered themselves up to Daesh as 'martyrs', completely available to act at any time, place and in any situation."
Police in Spain have long focused on prevention -- including nipping propaganda in the bud -- in its strategy to fight jihadism, with the adoption in 2015 of a law allowing authorities to detain people who merely consult jihadist websites.
According to the ministry, 163 alleged jihadists have been detained since 2015, when Spain increased its terror alert to four out of five.
But unlike France or Belgium, the country is less exposed to the return of nationals who went to fight abroad and plan to commit extremist acts on home soil.
Only around 200 Spaniards are estimated to have gone abroad to fight, compared to thousands from nearby France and Belgium.