ALGECIRAS, Spain — Before he boarded a Paris-bound train last week, armed with an assault rifle and the intent, the authorities say, to carry out a blood bath, Ayoub El Khazzani had spent the final chapter of his troubled time in Spain in this gritty port city, living in a run-down apartment block with his parents within walking distance of the local mosque.

The mosque, Taqwa, was under police surveillance from the first day work started on turning what had been an auto repair shop into a place of worship, Nordi Mohamed Ahmed, vice president of the association that runs the mosque, acknowledged in an interview.

But while the authorities point to the mosque as a crucial part of Mr. Khazzani’s transformation from onetime petty hashish dealer to someone suspected of being a radical, Mr. Mohamed Ahmed said the preaching here was not to blame.

“Women are also allowed to pray here,” he said, “which certainly wouldn’t happen if this was a radical place.”