The men -- all Moroccan nationals living in Madrid -- allegedly belong to a group tied to ISIS, according to the ministry.
"At the moment the cell was broken up, its members were fully radicalized and in a phase of total assimilation and commitment to the terrorist ideology -- demonstrating their full disposition to carry out an attack in Madrid," the ministry said in a statement.
Spain's national police acted because the cell's members were acting unpredictably and "had shown full willingness to ... carry out acts of terror," according to the agency.
The three men, who are between the ages of 26 and 29, were being interrogated in custody, an Interior Ministry representative said. Authorities can hold them for up to five days before pressing charges.
Source: Suspects radicalized while living in Madrid
The suspects became radicalized while living in Madrid over the past several years, a Spanish security source briefed by investigators told CNN.
The source said the three were inspired by ISIS, but were not actively working with or getting direction from the group.
The arrests come amid growing concern about links between that Islamist militant group, which has taken over vast swaths of Iraq
and Syria and also claimed credit for terror attacks elsewhere, and radicals in Spain, said Fernando Reinares, the head of the Elcano Royal Institute's Global Terrorism Program.
More than 80% of those arrested in Spain since 2013 for alleged jihadist activities tied to Syria
and Iraq were recruited by networks having some organizational connection with ISIS
, Reinares' program has found.
He said that more and more of these people -- 40% since 2013, compared with 5% over the previous 16 years -- were born in Spain, rather than having come to the country from elsewhere. And there's an increasingly higher percentage of both converts to Islam
Terror threats on the rise
In addition to threats from ETA, a Basque separatist group, Spain has dealt with serious, dangerous threats from Islamist militants in recent years.
The worst such example came in March 2004, when 191 people died
and more than 1,800 were injured in bombings targeting Spanish commuter trains. Prosecutors later claimed that the perpetrators were Islamic terrorists who were based in Spain but inspired by al Qaeda.
More recently, Spanish and Moroccan authorities arrested 14 people
in August on suspicion they'd been recruiting people to fight for ISIS in Syria and Iraq, according to Spain's Interior Ministry.
Those four, who are Spanish citizens of Moroccan origin, are "strongly radicalized" and had psychological and physical training, as well as weapons training, according to the minister.