TORONTO — An Ontario court on Wednesday quashed a bid to extradite Abdullah Khadr to the U.S. on terrorism charges following a lengthy legal battle between the federal government and one of Canada’s most controversial families.

Khadr, 29, who has been held for the past five years at a Toronto detention centre, was immediately released following the decision by Superior Court Justice Christopher Speyer.

Khadr is the eldest son of Ahmed Said Khadr, an al-Qaida financier who was killed by Pakistan forces in a shootout near the Afghanistan border in 2003. His family had immigrated to Canada in 1977.

“(I want to) try and get on with my life. I feel very happy,” Abdullah Khadr told reporters outside the downtown Toronto courthouse. “I always believed that it would happen one day, and thank God it happened.”

His release comes days before his younger brother, Omar, begins his military trial in Guantanamo Bay, Cuba.

Omar Khadr, 23, the only Canadian still held at the U.S. prison, has been detained there since 2002 following a firefight with U.S. forces in Afghanistan. He is charged with throwing a grenade that killed American medic Christopher Speer. He was 15 years old at the time.

From the start, Prime Minister Stephen Harper has refused to seek the repatriation of the terror suspect back to Canada but, notably, Canada’s legal system has sided many times with the Khadr family in its battles with the Canadian government.

In January, the Supreme Court of Canada ruled that Omar Khadr’s charter rights had been violated by Canadian officials who had questioned him at Guantanamo Bay in 2003 and 2004. Khadr had been exposed to sleep deprivation and denied his right to legal counsel by American interrogators.

Last month, a Federal Court judge ruled that the Conservative government had a week to come up with a list of “all untried remedies” that could help eradicate the breach of Khadr’s rights as a Canadian citizen. That victory was short-lived — a few weeks later, a Federal Appeals judge stayed the decision, arguing that the previous judge overstepped his boundaries and was essentially dictating the government foreign policy.

Meanwhile, the U.S. case against Abdullah Khadr was based on a number of statements he made to the FBI and RCMP about procuring weapons for al-Qaida and allegedly being involved in an assassination plot against the prime minister of Pakistan. He said those confessions were made while he was detained and tortured in Pakistan in 2005.

During his extradition hearing last fall, Khadr told a Toronto court that authorities had also threatened violence against his family.

“If someone tells you, if you don’t tell us you are selling missiles to al-Qaida, we are going to rape your sister, what would you say?” Khadr had asked, breaking down.

He told the court that he attended a camp in Afghanistan when he was 13 years old and learned how to use guns, explosives and rocket and grenade launchers. Khadr said these were not terrorism camps run by al-Qaida but were part of “Muslim culture.” He denied that his father had any influence over his ideology.

Nathan Whitling, one of the Edmonton-based defence lawyers representing Khadr, said this victory may have been the best-case scenario possible for his client but the battle is far from finished.

“We don’t feel that it’s over,” he said. “We see it as one good step in the process. Obviously we’re pleased about it but we’ll keep fighting this thing.”

The Canadian government has been on the “wrong side” these past five years by “actively pursuing” the extradition of his client to the U.S., added Whitling.

He and his colleague Dennis Edney had argued that Canada would be supporting interrogation methods against international law if it granted the extradition request. They also argued that the information was given under extreme duress.

Ultimately, Justice Speyer’s ruling was based on how the U.S. detained and drew a confession out of Khadr, who to this day maintains his innocence.

Khadr was arrested in Pakistan in 2004 after the U.S. government issued a $500,000 U.S. bounty for his capture. He was denied access to a lawyer for three months and held a total of 14 months in Pakistan without charges. During this time he was interrogated by Pakistani, Canadian and American officials.

Whitling said Khadr, fearing arrest by U.S. authorities, plans to stay in Canada.

In the meantime, he will enjoy the small pleasures in life. For his first meal outside of detention in five years, he ate an Asian stir-fry and drank a Pepsi.

“He’s getting married. He’s engaged,” said Whitling. “He just wants to settle down and live a quiet life.”

The federal government has 30 days to appeal the Ontario Superior Court ruling.

Carole Faindon, a spokeswoman for the Department of Justice, said it was too soon to say whether an appeal will be launched.

“We are reviewing the decision,” she said. “A decision on an appeal will be determined in due time.”