Spanish police and security authorities in Morocco "have dismantled a jihadist terrorist cell composed of six people", a ministry statement said, indicating that five of them were arrested in Morocco and one in Melilla, a Spanish enclave in North Africa.
The arrests came nearly three weeks after a group of jihadists, many of them of Moroccan origin, killed 16 people in two deadly attacks using vehicles and knives in Barcelona and another seaside resort in northeastern Spain.
"An investigation by the Moroccan security services found evidence that this group was planning large-scale terror attacks, holding discreet nighttime meetings during which they carried out physical training and simulated murder by decapitation," the ministry said.
A similar statement issued by the Moroccan interior ministry and quoted by MAP news agency, referred to group members "training how to slit throats with knives."
The agency said the cell became active in Beni Chiker, a town in the northeastern province of Nador, with its members "planning to carry out a range of execution operations in Morocco and Spain."
Five of the suspects are Moroccan nationals, one of whom had residency in Spain, while the sixth was a Spanish national of Moroccan origin, it said.
Police in Spain said the leader of the cell was a 39-year-old Spaniard of Moroccan origin living in Melilla. He was arrested by the security forces while visiting Morocco.
"He used his position as an assistant teacher in a centre for reeducating minors to carry out recruitment activities and to radicalise young people in a vulnerable situation," the interior ministry said.
It said such activity was "in line with the global strategy" of the Islamic State group.
Since mid-2015, Spain has arrested 199 people accused of links to extremism, the ministry said.