“The community doesn’t have problems,” she said. “Why did they do these things?”

There is much that investigators have yet to learn, but based on interviews with the men’s friends, neighbors, religious figures and the police, the answer appears to lie at least in part with a shadowy figure linked to the Islamic State, Abdelbaki Essati, who is believed to have been killed on Wednesday, a day before the attack, when explosives that the group was manufacturing accidentally detonated.

Mr. Essati, who was in his 40s and who is reported to have had links to Islamist extremists going back at least a decade, somehow brought the young men under his influence after establishing himself as an imam in their mountain town of Ripoll, even though few of the young men had a history of regularly attending mosque.

In an eerie resemblance to recent attacks in Paris and Brussels, Mr. Essati appears to have targeted groups of brothers, perhaps because family ties make it harder for individuals to leave the group, even if they want to go to the police.

Of the four sets of brothers involved in the attacks in Catalonia, one family may even have had three brothers active in the cell, investigators believe. In the Paris and Brussels attacks, there were at least two sets of brothers involved.