A federal judge barred prosecutors on Wednesday from using a crucial witness in the first trial of a former Guantánamo detainee, adding to the fierce debate over whether the government can successfully prosecute terrorist detainees in civilian court.

The trial of Ahmed Khalfan Ghailani, who faces charges in the 1998 bombings of two United States Embassies in East Africa, has been seen as a test of President Obama’s goal of moving many other detainees, like Khalid Shaikh Mohammed, into federal court and, ultimately, closing Guantánamo.

In the months since Mr. Ghailani was brought to New York from Guantánamo Bay, Cuba, Judge Lewis A. Kaplan of United States District Court in Manhattan has rejected defense requests to dismiss the case because of violations of Mr. Ghailani’s right to a speedy trial and because of accusations he was tortured.

But just as the trial was to begin on Wednesday, Judge Kaplan ruled that he would not allow the witness to testify. He noted that the government had acknowledged that it had identified and located the witness through interrogation of Mr. Ghailani when he was earlier held in a secret overseas jail run by the Central Intelligence Agency. His lawyers have said he was tortured there.