By Erik Kirschbaum, Joseph Nasr and Joern Poltz

ANSBACH, Germany (Reuters) - Mohammad Daleel made a mess of his escape from Syria to Europe three years ago - he was detained and fingerprinted in Bulgaria before a mysterious benefactor gave him a free plane ticket to help him get to Germany.

The 27-year-old also bungled a suicide bomb attack in the Bavarian town of Ansbach on Sunday, days before he was to be deported back to Bulgaria. He first failed to get past ticket collectors into an open-air concert packed with 2,500 music lovers and then set off the detonator but not the bomb itself.

Daleel killed himself in the attack carried out in the name of Islamic State and injured 15 people in a crowded wine bar next to the entrance of the concert, but his heavy black backpack packed with explosives and shrapnel failed to go off.

The partial explosion destroyed the table and chair he was sitting at, and caused lacerations to several patrons nearby. But most of the glasses on nearby tables remained upright and hardly any of the courtyard's windows were damaged.

"It wasn't a bomb that went off, it was only the trigger," said Ralph Millsaps, a retired U.S. army officer who was drinking wine at a table just six meters away from Daleel at Eugen's Weinstube bar, and was left with deep cuts on his side from wooden splinters.

"We're extremely fortunate that the main charge didn't go off," Millsaps told Reuters in his soft North Carolina twang. "There were 25 people in the courtyard of the wine bar and another 30 outside on the alley in front. We wouldn't be here anymore if the bomb had gone off."

The attack has prompted further criticism and concern about Chancellor Angela Merkel's open-door refugee policy, which has seen more than a million migrants enter Germany in the past year, many fleeing war in Syria, Iraq and Afghanistan.

Her political opponents say the policy has allowed Islamist militancy to take hold in the country, while there is growing fear among the general public.

The picture of Daleel that emerged from a dozen interviews in Ansbach, a pleasant cobblestone-street town of 41,000, is one of stark contrasts.

Much is unclear, including whether the Syrian came to Europe with the intention of carrying out an attack, or was "radicalized" while in the West; and whether his actions were driven by ideology, mental illness or a combination of both.

At the three-storey refugee shelter where he lived, on a hill overlooking the town, many of those who knew him described a quiet but friendly young man, a loner with long black hair who kept mostly to himself. They said he spoke English fairly well, and was eager to find a job and start a new life in Germany.

But another character has also surfaced: a shrewd figure who managed to foil previous attempts by German authorities to deport him back to Bulgaria – his first documented point of entry into the European Union – by exploiting legal loopholes.

What drove Daleel to try to commit mass murder is also unclear.

Investigators found a video on Daleel's phone in which he pledged allegiance to Islamic State and are examining whether he might have been sent to Germany as part of a "sleeper cell".

Yet those who knew him at the shelter said he was not particularly religious, a sentiment echoed by his psychotherapist Gisela von Maltitz, who is based in the town of Lindau, a two-hour train journey from Ansbach. She said Daleel was mentally scarred and left suicidal by the death of his wife and son in Syria and by being tortured.

'RAMBO'

"We called him 'Rambo' because of his long hair and muscles," said Mahmood Mubaritz, who lived in the same refugee shelter, adding that he bore a resemblance to American actor Sylvester Stallone.

"He had very strong arms and liked to wear tight, sleeveless shirts. He wanted to show us he was a strongman."

Mubaritz, who came to Germany four years ago from Pakistan, said he could not fathom how the quiet man he knew could have carried out such an attack. He lived with Daleel and 26 others over the past year in a former budget hotel that was converted into the shelter to house an influx of migrants.

The shelter's name is actually "Hotel Christl" but the "l" was broken off and the giant sign atop the rundown building now reads: "Hotel Christ."

A spate of attacks in Germany since July 18 has left 15 people dead and dozens injured. Last week a 17-year-old refugee from either Pakistan or Afghanistan who had links to Islamist militancy attacked and stabbed four tourists from Hong Kong on a train near the Bavarian town of Wurzburg, about 80 km from Ansbach.

Investigators of the Ansbach bombing are trying to find out when Daleel might have been recruited by Islamic State, and who may have supported him in Germany and ordered him to carry out the attack.

Authorities searching his room at the Hotel Christl found diesel fuel, hydrochloric acid, alcohol, batteries, paint thinner and pebbles – the same materials used in the bomb – along with computer images and film clips linked to the jihadist group, and a substantial amount of cash far in excess of what refugees receive from the German government.

Investigators said he had an "intensive" phone message exchange with someone who was in the Middle East shortly before the blast. "The exchange appears to have ended immediately just before the attack," said Bavaria's state interior minister Joachim Herrmann.

Authorities are also looking into Daleel's account of his journey to Germany, documented during sessions by psychotherapist Von Maltitz, managing director of the Exilio refugee support group which offers mental health services to migrants.

Daleel told von Maltitz that a benefactor paid for his passage from Bulgaria to Austria, from where he traveled over the border to Germany. "Fortunately I found a Syrian man who bought an airplane ticket for me to Austria," he said.

Investigators will likely seek to shed light on who the benefactor was, as well as other unknowns, including why Daleel was detained in Bulgaria and subsequently released.

'SUICIDAL'

Despite Daleel's professed allegiance to Islamic State, von Maltitz said she had seen no indication of any link to radical Islamist ideology, or religion at all.

"A connection to Islam doesn't match the picture I had of him at all," said the therapist, who added she had 40 sessions with Daleel between May 2015 and January this year. "He never made any kind of comment in that direction at all, about Islam or any other religion."

"He had been badly tortured in Syria," she said. "His wife and small child had been killed in Syria when a building collapsed on them after an explosion. In Bulgaria he was in prison and maltreated," she added. "We're certain that the information he supplied was truthful."

Von Maltitz, who said Daleel's death had freed her from patient confidentiality obligations, had scheduled further appointments with him for this week but he had postponed them until Aug. 1.

The therapist said she repeatedly intervened with authorities not to deport him. "He was suicidal," she said, adding that the prospect of deportation to Bulgaria "scared him horribly".

Mubaritz at the refugee shelter also said Daleel had shown no overt signs of religious faith. "I never saw him praying," he said. "He was definitely not a fanatical Muslim."

He said he had talked with the Syrian about how to find a job in Germany and encouraged him to apply at the McDonalds restaurant in town where he worked as a cook and cashier.

They talked sometimes in the communal kitchen or on the terrace in front of the shelter, where Daleel also helped repair the bicycles of other refugees.

"He was always smiling and always seemed to be happy even though he was alone most of the time and tended to stay in his room," said Mubaritz. "I think he was eager to find a job in Germany and stay here."

'HUMAN BEING'

A 21-year-old Ethiopian refugee who gave his name as Jamal Hassan said the Daleel he remembered at the shelter was more of a brooding character.

"He seemed serious and kept to himself," said Hassan, who came to Germany six months ago after crossing the Mediterranean from Libya to Italy. "I never saw him smiling."

A German teenager living across from the shelter said Daleel was known in the neighborhood as a friendly man who liked to watch the world go by from his top-floor flat.

"I thought he was a nice guy," said Nick Geier, 14. "He used to smile and say hello. He certainly didn't look like someone who would do something like this. I'm really afraid now."

Geier's father Alexander, 41, added: "We were stunned when we heard what he had done."

Daleel had hired a lawyer to help him successfully defeat two attempts by German authorities to send him to back to Bulgaria, citing his mental instability, according to his therapist.

But his bid to stay eventually failed this month, and his deportation notice was issued on July 13.

Eleven days later, he carried out his attack.

He died from internal injuries suffered from the blast even though an off-duty German nurse rushed to try to save him and three days later was still going through a jumble of emotions about the attack.

"Almost everyone at the wine bar had run inside but I saw one man lying on the ground," the woman, who asked to be called Sabine, said in an interview. "I didn't know he was the attacker. I just thought he was someone who had been overlooked in all the chaos. There wasn't any pulse in his wrist but I felt a pulse in his neck."

She said she tried to keep him alive until rescue crews arrived moments later even though it was all for naught.

"Anyone else would have helped him too," she said. "I really can't understand those who said 'he's a terrorist, let him die'. In my eyes he was a human being."

(Editing by Pravin Char)