OTTAWA — Despite a vigorous protest from the Canadian government, a court in Alberta released Omar Khadr, a former child soldier in Afghanistan, on bail Thursday while he appeals his conviction by an American military tribunal.

Mr. Khadr, the only Canadian to be held at the Guantánamo Bay detention center in Cuba, was free for the first time since 2002. He was 15 when he was captured by American forces during a battle in Afghanistan. He pleaded guilty in 2010 to charges that he used a grenade to kill an American soldier, Sgt. Christopher Speer, during the battle, which left Mr. Khadr severely wounded.

Canada’s Conservative government reluctantly allowed Mr. Khadr to be transferred to Canada in 2012 to serve the remainder of his eight-year sentence in an Alberta prison.

Mr. Khadr, who is now 28, has repudiated his guilty plea, saying he entered it solely to get out of Guantánamo Bay. But he has not denied throwing the grenade. Instead, he maintains that he did so out of fear, and without any intent to kill Sergeant Speer.