Police arrested the trio, legal residents of Spain between the ages of 26 and 29, in pre-dawn raids in two neighbourhoods of the capital Madrid, the interior ministry said in a statement.
"National police broke up in Madrid an active jihadist terrorist cell," it said.
It added that authorities acted quickly to detain the men because "their reactions were very unpredictable" and they had "manifested their clear willingness to carry out an attack in Madrid".
"Their goal was to act in Spain," he said on Cadena Ser radio.
More From This Section
The suspects "were ready to conduct indiscriminate attacks", including knife attacks like those recently conducted by Palestinian militants in Israel or deadly assaults with rifles, he added.
The cell's leader recruited others by spreading IS doctrine while the other two detained men were "operatives" in charge of carrying out potential attacks, the interior ministry said.
No weapons were seized during the operation. The investigation remains open, the ministry said.
Like other European nations, Spain has been grappling with a growing number of jihadist cells on its territory and radicalised Muslims leaving to fight for IS or other Islamist groups in Iraq and Syria.
More than 100 people from Spain are suspected of having joined jihadist fighters in Iraq and Syria and authorities fear they may return to launch attacks.