WASHINGTON - A federal appeals court on Friday overturned an order releasing a Yemeni detainee from Guantanamo Bay and ruled that circumstantial evidence of terrorist ties can be enough to keep a prisoner.

Government attorneys argued that Hussain Salem Mohammad Almerfedi stayed at an al-Qaeda-affiliated guesthouse, based on the testimony of another Guantanamo detainee. A lower-court judge found the testimony unreliable and ordered Almerfedi released, but the U.S. Circuit Court of Appeals in Washington said the judge erred in that conclusion.

The circumstances of Almerfedi's capture were not clearly explained in court records. He was apprehended in Tehran, Iran, after the terrorist attacks on Sept. 11, 2001. Iranian officials turned him over to Afghan authorities in March 2002 in a prisoner exchange. In May 2003, U.S. forces moved him to Guantanamo Bay, where he has remained since.

Almerfedi said he left his home in southern Yemen in 2001 to seek a better life in Europe with about $2,000 he earned doing odd jobs and selling a narcotic plant called khat. He said he bribed a guard at the Pakistan Embassy to get a visa and went to Lahore, Pakistan. He stayed several weeks at the headquarters of Jama'at Tablighi, which the United States has designated as a terrorist support entity.

He said he paid another Arabic speaker he met at the headquarters most of his life savings to smuggle him into Iran, then Turkey, and eventually to Greece. The pair went to the Iranian border and bribed the guards to let them cross. But instead of heading for Turkey, they went 500 miles east in the opposite direction to Mashad, Iran, where they spent a month.

Almerfedi said he was simply following his traveling companion and eventually complained, so they moved on to Tehran. He was apprehended there, with about $2,000 cash on him.

The appeals court also found Almerfedi's own explanations for his travel unconvincing and agreed with the government that his stay at the Jama'at Tablighi headquarters, his route away from Europe and his unexplained $2,000 cash when he was captured suggested he was part of al-Qaeda.

"We consistently have found such circumstantial evidence damning," the appeals court ruling said.