A federal court Tuesday threw out the terrorism conviction of Osama bin Laden’s former bodyguard and driver, ruling that he was improperly prosecuted before a military tribunal for a war crime that did not exist at the time he was accused of having committed it.

The unanimous decision by a three-judge appeals panel came in the case of Salim Ahmed Hamdan, who authorities say met bin Laden in 1996 at an al-Qaeda training camp.

Hamdan was tried in 2008 before a military commission at the U.S. prison at Guantanamo Bay, Cuba. He was acquitted of conspiracy but convicted of material support of terrorism; he was sentenced to 5 1 / 2 years in prison and released in 2009 to his family in Yemen.

In seeking to overturn his conviction, Hamdan argued that material support of terrorism was not considered a war crime under international law when he was accused of aiding al-Qaeda. In a 28-page ruling, Judge Brett M. Kavanaugh of the U.S. Court of Appeals for the D.C. Circuit agreed.

“If the Government wanted to charge Hamdan with aiding and abetting terrorism or some other war crime that was sufficiently rooted in the international law of war . . . it should have done so,” wrote Kavanaugh, who was joined by Chief Judge David B. Sentelle and Senior Judge Douglas H. Ginsburg.

This undated file photo shows Salim Hamdan. A federal appeals court on Tuesday threw out the conviction of Hamdan, a former driver for Osama bin Laden who served a prison term for material support for terrorism. (Anonymous/AP)

Joseph McMillan, an attorney for Hamdan, praised the decision, saying, “We are gratified that even in the midst of the perceived national emergency the American courts are prepared to uphold the rule of law in that way and insist that we proceed with accordance of law.”

McMillan said Hamdan had not learned of the ruling as of Tuesday afternoon.

Dean Boyd, a Justice Department spokesman, said the government was reviewing the decision and declined to comment further.

The opinion hinged largely on the centuries-old “ex post facto” legal principle, which ensures that defendants are not charged retroactively with crimes that were not considered offenses at the time they were allegedly committed. Hamdan was charged under the 2006 Military Commissions Act, a law that authorized the government to try detainees before military tribunals for war crimes.

The appeals court determined that lawmakers were cognizant of the Constitution’s prohibition on “ex post facto” laws and believed that material support of terrorism was “a pre-existing crime under the law of war” when they specified that offense and others in the 2006 act. But the legislators were wrong, the court found. “There is no international-law proscription of material support for terrorism,” Kavanaugh wrote.

It is not clear how the ruling will affect other cases before military commissions. There are 166 detainees at Guantanamo. The Pentagon has cleared 87 for release or transfer abroad, and the rest could stand trial.

Among those facing charges before a military commission is Khalid Sheik Mohammed, the alleged mastermind of the Sept. 11, 2001, terrorist attacks.

Robert Chesney, a University of Texas law professor who specializes in national security matters, said the decision would probably have a limited effect on future cases because it “only applies to pre-2006 conduct, and at the moment there are few cases involving material support charges in military commissions.”

Even if detainees’ cases fall apart before the commissions, it is unlikely that the government will be forced to free any prisoners. The U.S. Court of Appeals for the D.C. Circuit has granted authorities generous leeway in detaining prisoners, and Kavanaugh took pains to note that “our judgment would not preclude the detention of Hamdan until the end of U.S. hostilities against al Qaeda.”

Kavanaugh also noted that the ruling would not preclude “appropriate criminal charges in a civilian court.”