By Tarek Amara and Mohamed Argoubi
TUNIS (Reuters) - The suicide bomber in Tunisia who blew himself up in a bus packed with presidential guards on Tuesday had been arrested by police before on suspicion of jihadist 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 in the region after its 2011 uprising that ousted autocrat Zine Abidine Ben Ali.
Houssem Abdelli, a street vendor from an impoverished neighborhood of Tunis, detonated his explosives as presidential guards boarded a bus on Tuesday afternoon on one of the capital's main boulevards, killing 12 people.
The potential missed opportunity to stop a suicide bomber - despite authorities finding jihadist 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 before him and the Tunisians who left to fight for militant groups in Iraq and Syria, Abdelli appears to have followed a familiar path from young man who showed few signs of his new violent ideology.
All three of this year's major attacks in Tunisia have been claimed by Islamic State, 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 jihadist camps in Libya.
"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.
Neighbors said Abdelli was arrested in August. Officials declined to give precise dates for his arrest and release.
Tuesday's attack was the first suicide bombing in the capital and forced the government to implement a curfew, declare a state of emergency and promise harsh measures to protect against jihadists returning from war zones.
Authorities said on 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.
More than 3,000 Tunisians are now fighting for Islamic State or other militant groups in Iraq, Syria and neighboring Libya. Some have threatened to return to stage attacks in Tunisia.
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 jihadist literature in his possession, officials said.
Neighbors in his poor district near Tunis' Ettadhammen area said until a few years ago he enjoyed soccer 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 any more and spent most of the time in the mosque or at one of the koranic schools."
Mohamed, a neighbor, also remembers the change in the last few years. He said Abdelli spent a lot of time selling small cakes outside the mosque from a small cart.
"He was arrested after they found propaganda in his house calling for jihad in Iraq and Syria, but they freed him quickly," said Mohamed.
One of the victims of Abdelli's bombing lived in the same poor neighborhood. Omar Katayi was one of the guards on board the same bus where Abdelli detonated his explosives.
One local woman said she had seen Abdelli just last week in jeans and with his beard shaved off, perhaps, she said, not to attract attention with his usual more conservative appearance.
"We are all in shock," said neighbor Fatma Ben Saleh. "We all know his mother and father. They were just a normal family."
(Writing by Patrick Markey; Editing by Hugh Lawson)