TORONTO (AP) — A former Guantanamo Bay inmate convicted of killing a U.S. soldier was released on bail Thursday after a judge refused a last-ditch attempt by the Canadian government to keep him imprisoned.

Court of Appeal Justice Myra Bielby rejected the government’s emergency request to stop Omar Khadr release’s while he appeals his U.S. war crimes conviction. A lower court judge granted him bail last month.

“Mr. Khadr you’re free to go,” Bielby said before cheers erupted in the courtroom. Khadr smiled.

Toronto-born Khadr spent a decade in the U.S. prison at Guantanamo Bay, Cuba. Since 2012 he’s been held in Canada, serving out an eight-year sentence handed down by a U.S. military commission in 2010. He was convicted of war crimes, including throwing a grenade when he was 15 years old that killed U.S. Army Sgt. 1st Class Christopher Speer in Afghanistan during a 2002 firefight

Khadr was once the youngest detainee at Guantanamo, arriving there at age 15. He is now 28.

Khadr’s long-time lawyer Dennis Edney and his wife have offered to take him into their home. Among the bail conditions imposed were that Khadr wear a tracking bracelet, live with the Edneys, observe a curfew between 10 p.m. and 7 a.m., and have only supervised access to the Internet. Also, he can communicate with his family in Ontario only while under supervision and only in English.

“He’s met very few people outside a jail cell,” said Nate Whitling, one of Khadr’s lawyers.

“It’s going to be a major adjustment for him, but I’m sure he’s up for it.”

Whitling said Khadr has served his time and he believes this will be the end of his incarceration. Whitling later tweeted a picture of Khadr leaving the courthouse with Edney.

“I’m delighted. It’s taken too many years to get to this point,” Edney said. “We were the only Western country that didn’t request one of its detainees come home. We left a Canadian child in Guantanamo Bay to suffer torture.”

Edney asked why Canada is spending money helping to rehabilitate child soldiers in Sierra Leone “while we had one here.”

Defense attorneys said Khadr was pushed into war by his father, Ahmed Said Khadr, an alleged senior al-Qaida financier whose family stayed with Osama bin Laden briefly when Omar Khadr was a boy. His Egyptian-born father was killed in 2003 in a Pakistani military operation.

Canadian Prime Minister Stephen Harper’s Conservative government has long refused to support Omar Khadr, reflecting ambivalence in Canada over the Khadr family.

The government had argued that releasing Khadr from an Alberta prison would undermine the treaty under which the U.S. returned him to Canada to serve out his eight-year sentence in 2012.

“We are disappointed with today’s decision, and regret that a convicted terrorist has been allowed back into Canadian society without having served his full sentence,” said Jeremy Laurin, a spokesman for Canada’s public safety minister.

U.S. State Department spokesman Jeff Rathke declined to immediately comment on the judge’s decision.

Khadr’s lawyers said he’s been a model prisoner. They produced documents including a recent interview Khadr did with a prison psychologist in which he denounces terrorism and says he wants to win people’s trust and respect.

“I’ve screwed up in the past, and I’m worried it will haunt me,” Khadr told the psychologist. “People will think I’m the same person as I was 12 or 13 years ago.”