The suicide bomber in Tunisia who blew himself up in a bus packed with presidential guards Tuesday had been arrested by police before on suspicion of extremist ties but was released for lack of evidence, a security official said. Tunisia, one of the Arab world's most secular nations, is struggling to counter Islamist militancy since becoming a beacon of democratic change after its 2011 uprising. Houssem Abdelli, a street vendor from an impoverished neighborhood of Tunis, detonated his explosives as presidential guards boarded a bus Tuesday on one of the capital's main boulevards, killing 12 people. The potential missed opportunity to stop a suicide bomber – despite authorities finding jihadi literature in his house and neighbors noticing changes in his behavior over the last few years – shows how security forces are struggling to prevent attacks. Abdelli's bus bombing follows massacres targeting a Sousse resort hotel and the Bardo national museum in Tunis earlier this year. Like other homegrown attackers and the Tunisians who left to fight for militants in Iraq and Syria, Abdelli appears to have followed a familiar path from a young man who showed few signs of his new violent ideology. All three of this year's attacks in Tunisia have been claimed by ISIS, the militant group controlling large parts of Iraq and Syria. All three were carried out by Tunisians who appear to have been radicalized at home or trained in militant camps in Libya. More than 3,000 Tunisians are now fighting for ISIS or other militant groups in Iraq, Syria and neighboring Libya. Some have threatened to return to stage attacks in Tunisia. "This terrorist was arrested by the police and then freed by the justice system for lack of evidence," Interior Ministry Security Chief Rafik Chelli told local radio. British Foreign Secretary Philip Hammond acknowledged that Libya posed a "threat," during a visit Friday to Tunis where he met his Tunisian counterpart Taieb Baccouche and other officials. "Your minister mentioned the challenges in your neighbor Libya and we are acutely conscious of the threat that your country faces from what's going on in Libya," he said. Neighbors said Abdelli was arrested in August. Officials declined to give precise dates for his arrest. Tuesday's attack was the first suicide bombing in the capital and led to implement a curfew, declare a state of emergency and promise harsh measures to protect against jihadists returning from war zones. Authorities said Friday they had arrested 40 people with suspected links to militant groups, and had issued 92 house arrest orders for people suspected of returning from Syria, Iraq and Libya. It was not clear whether Abdelli had left the country to fight overseas or train before he carried out his attack. Police had arrested him after finding extremist literature in his possession, officials said. Neighbors in his poor district near Tunis' Ettadhammen area said until a few years ago he enjoyed football enough to earn himself the nickname "Pele" after the Brazilian star. "We used to play football together," his cousin Atef said. "He changed about 3 years ago, and he started to avoid us. He became isolated in the neighborhood. He would not talk to girls anymore and spent most of the time in the mosque or at one of the quranic schools." Mohammad, a neighbor, also remembers the change in the last few years. He said Abdelli spent a lot of time selling cake outside the mosque. "He was arrested after they found propaganda in his house calling for jihad in Iraq and Syria, but they freed him quickly," Mohammad said. One of the victims of Abdelli's bombing lived in the same poor neighborhood. Omar Katayi was one of the guards on board the bus where Abdelli detonated his explosives. One local woman said she had seen Abdelli last week in jeans and with his beard shaved off, perhaps not to attract attention with his usual more conservative appearance. "We are all in shock," neighbor Fatma Ben Saleh said. "We all know his mother and father. They were just a normal family."