Police in Spain have arrested three Moroccans, including a suspected member of Islamic State considered to be a clear threat to national security, the interior ministry said.
The suspect had instruction manuals on jihadi suicide and electronic terrorism and was believed to have had internet contact with IS members in Syria and Iraq, a ministry statement said.
The ministry said he had an extremely dangerous profile similar to those involved in recent attacks in Britain and France and was considered a threat to Spain.
"We have nothing to indicate he was going to attack immediately but it's certain his radicalisation was extreme and he had all the training and information to carry out an attack," interior minister Juan Ignacio Zoido told Spanish National Television.
The minister said the suspect was indoctrinating and training the other two arrested.
The detainees, aged between 32 and 38, lived together in a residential area of Madrid, police said.
Police video showed two of the three being arrested as they came out of a building before dawn wearing motorbike helmets and moments later heavily armed agents entering the building.
The statement said Spanish police have been involved in the arrests of 172 suspected jihadi activists since the country raised its security alert to one step below the maximum in June 2015.