MONTREAL -- A Quebec man accused of wanting to leave Canada to join the Islamic State in Syria says he was desperate to reach his wife and young kids and get them away from his dangerous, threatening brother-in-law.

Ismael Habib began testifying in his own defence Wednesday at his trial on terror-related charges.

Habib, 29, is charged with attempting to leave the country to participate in the activities of a terrorist group, as well as giving false information in an effort to obtain a passport.

The Crown has demonstrated that Habib told undercover RCMP officers twice during an elaborate sting operation in 2016 that he wanted to travel to Syria to join the Islamic State and take part in jihad.

But Habib denied Wednesday having terrorism goals and said his only desire was to track down his family he believed were being threatened by his brother-in-law somewhere in the region.

Having his passport revoked due to a previous federal terror probe, Habib said he was willing to do anything to get to his family.

Habib, in rambling and sometimes tearful testimony, said his brother-in-law was upset because the accused's wife had intervened in 2015 to help her sister, who was allegedly caught in a violent and brutal marriage with the man in Turkey.

The brother-in-law began to threaten Habib, who said communication with his wife went from daily chats to one brief call a month from parts unknown.

Between June 2015 and his arrest in February 2016, his wife pleaded with Habib during short exchanges to help her and their two young children, a four-year-old girl and a three-year-old boy.

"I have no idea where she is -- if she's in Turkey, if she's in Syria," said Habib, his voice cracking. "If I had to go to Turkey to get her, I'd go. If I had to go to Syria and go through hell, I'd go."

Habib told the court his life was turned upside down when that same brother-in-law came to him in a panic in late 2012 and informed him he and others were the subject of an RCMP probe.

"From that moment, it messed up my life," Habib said. "It broke all my dreams, it created a load of problems."

His brother-in-law fled Canada, while Habib, after a number of failed attempts and struggles with the stress of being under investigation, managed to leave Canada in 2013, first for Algeria, then Turkey and finally Syria.

Habib recounted being with his brother-in-law for a few months in a Syrian town occupied by as many as 70 militant groups.

There was no fighting in the area, however, and he testified he didn't join any group.

Habib was eventually detained upon returning to Turkey and then sent back to Canada.

The son of a Quebec mother and Afghan father, Habib disputes having terrorist leanings, telling the court he's against the Islamic State's willingness to kill anyone.

"I don't want to go with them to kill innocent people," he said. "Would I kill my mother? I wouldn't do that."

For eight months between September 2014 and May 2015, his phone was tapped by federal authorities.

Habib examined the transcripts closely before the trial began and suggested they back up his claim.

"Not one time was there a mention of the word jihad, the word Syria, the word combat, the word Islamic, the name al-Qaida," Habib said.