The alleged involvement in last week’s terrorist attacks in Spain of a number of Moroccan nationals—one of whom is still at large—has Western security officials fretting over how deeply radical Islamic groups have penetrated a community of four million spread across the European Union.

Spanish authorities have said most of the 12-strong network they believe plotted and conducted Thursday’s rampages in and near Barcelona were Moroccan nationals or of Moroccan descent. Islamic State has claimed responsibility for the attacks...