Omar Khadr should be serving his time in a provincial facility and must be transferred from federal prison, the Alberta Court of Appeal ruled Tuesday.

Khadr, a Canadian who pleaded guilty in a U.S. military court to war-crimes charges, would have been sentenced as a youth had he been in Canada, the judges wrote. That means Khadr would have served his time in a provincial jail, the judges said, and should be sent there now.

The federal government says it will seek permission to appeal the ruling and will seek a stay of the order, a position that was later supported in a statement by Alberta's justice minister.

Khadr, 27, was transferred to Canada in September 2012 under the International Transfer of Offenders Act to serve out the remainder of his eight-year sentence, which ends in October 2018.

"We conclude that Khadr ought to have been placed in a provincial correctional facility for adults," wrote Justices Catherine Fraser, Jack Watson and Myra Bielby.

"In summary, the eight-year sentence imposed on Khadr in the United States could only have been available as a youth sentence under Canadian law, and not an adult one, had the offences been committed in Canada."

Dennis Edney, Khadr's longtime lawyer, said the federal government "chose to misinterpret" the international transfer of offenders law.

"We are pleased to get Omar Khadr out of the hands of the Harper government. This is a long series of judgments against this intractable, hostile government.

"It would rather pander to politics than to apply the rule of law fairly to each and every Canadian citizen," Edney said in a statement.

Khadr spent the first seven months of his time in Canadian prison in solitary confinement, Edney noted.

Another lawyer for Khadr, Nathan Whitling, said the ruling also means his client can now apply to have his sentence reviewed by a youth court judge, as well as the National Parole Board.

"A youth sentence carries many advantages under Canadian law," Whitling told Rosemary Barton on CBC News Network's Power & Politics. "Such sentences are designed to rehabilitate and reintegrate people like Omar in recognition of the fact that the events occurred when they were youths.

"The law of Canada confirms that youths, like Omar, have diminished culpability for the actions that occur when they are children under the law."

Government to appeal

Edney said Khadr's transfer to a provincial facility could normally occur within a few weeks.

But the federal government said in a statement it would appeal the ruling "and seek a stay to ensure that [Khadr] stays in federal prison — where he belongs."

"Omar Ahmed Khadr pleaded guilty to heinous crimes, including the murder of American army medic Sgt. Christopher Speer. We have vigorously defended against any attempt to lessen his punishment for these crimes," Public Safety Minister Steven Blaney said in the statement.

"We do not agree that a youth sentence is appropriate for someone who is seen on video making the same type of improvised explosive devices that killed many of the 158 Canadian Armed Forces members who died in Afghanistan," the statement said.

Françoise Boivin, the NDP's justice critic, said the court found that Khadr should have been sentenced as a youth and the decision should be respected. She added that the government should think twice before seeking appeal before the Supreme Court.

"The Conservative government is starting to cost us a lot of money in all their court challenges that they seem to lose one after the other," she said.

Khadr was detained in 2002 at age 15 after a deadly firefight in Afghanistan between U.S. forces and militants, in which a U.S. soldier was killed. Khadr, whose father was a senior member of al-Qaeda, was declared an unlawful enemy combatant and charged by the U.S. in 2005.

He agreed to plead guilty to five offences — including murder in violation of the law of war, attempted murder in violation of the law of war and conspiracy in attacks on U.S. forces — in 2010, shortly after the start of his trial at the U.S. military base in Guantanamo Bay, Cuba, in exchange for assurances his sentence would not exceed eight years.

After his transfer in 2012, Khadr was sent to Millhaven Institution near Kingston, Ont., before being moved to the Edmonton Institution and later Bowden Institution in Innisfail, Alta.

Khadr challenged his detention in the federal system, filing an application for habeas corpus. That application was rejected by the Alberta courts.

But in Tuesday's ruling, the judges found that a lower court judge erred when he ruled Khadr was serving five concurrent sentences, and that four of them were adult sentences, meaning he could be held in a federal institution.