GUANTÁNAMO BAY, Cuba — On the witness stand was James E. Mitchell, a psychologist and architect of the Bush-era interrogation program that had inflicted torture on prisoners held in secret C.I.A. prisons after the Sept. 11, 2001, attacks.
Defiantly, he described how the program came about and why in his view it was necessary, growing emotional only when recounting how he came to the conclusion that it was his patriotic duty to personally implement the techniques he had devised.
Sitting yards from him in the military courtroom built specifically for their death-penalty trial were the five men accused of helping plot the attacks. All of them had been subject to the methods developed by Dr. Mitchell. Their alleged leader, Khalid Shaikh Mohammed, was waterboarded 183 times in March 2003 by a team including Dr. Mitchell. They sat impassively as he testified at a pretrial hearing in their case.
It was an extraordinary moment in the slow-moving justice system set up to try foreign prisoners of the war on terror, with American lawyers for defendants who were tortured more than a decade and a half ago flipping the script to question an interrogator from the so-called black sites.
Dr. Mitchell, a former contract psychologist for the C.I.A., expressed no regrets or contrition, tearfully saying he did it for the American people at a time when President George W. Bush’s administration feared a follow-on attack by airplane or nuclear bomb to the Sept. 11 hijackings that killed 2,976 people.
“I’d get up today and do it again,” he said.
“I thought my moral duty,” he said, choking up, “to protect American lives outweighed the feelings of discomfort of terrorists who voluntarily took up arms against us. To me it just seemed like it would be dereliction of my moral responsibilities.”
He was talking about the first man he waterboarded, a Palestinian known as Abu Zubaydah. In 2002, Mr. Zubaydah was the first known C.I.A. prisoner subjected to the full range of interrogation techniques, which also included sleep deprivation and being crammed inside a coffin-size box and slammed into a wall. He has never been charged with a crime and has never been to the war court but is held at Guantánamo as an indefinite detainee.
But the five men charged as conspirators in the Sept. 11 attacks were present. It was the first time they had seen Dr. Mitchell since their transfer to Guantánamo from the black sites in 2007. Lawyers for Mr. Mohammed and another defendant, Walid bin Attash, asked the judge to clear two thick binders of materials off the witness stand that had obstructed their view of him.
None of the defendants expressed any visible emotion, although defense lawyers had a psychologist and a psychiatrist with experience treating torture survivors in court to sit with two of them.
Lawyers for Mr. Mohammed’s nephew, Ammar al-Baluchi, called Dr. Mitchell to testify in a long-running defense effort to show the interrogation program was a Bush administration-wide effort and persuade the judge to exclude subsequent F.B.I. interrogations of the defendants at Guantánamo in 2007 from their trial. It is scheduled to get underway next January.
By law, prosecutors cannot use what the men told Dr. Mitchell and other interrogators in the C.I.A. prison as evidence in the death-penalty trial. Prosecutors consider the F.B.I. interrogations to be crucial case evidence.
Dr. Mitchell described the decision to use waterboarding and other “coercive physical pressure” as born of a climate that feared Al Qaeda was plotting a nuclear attack on the United States, or plotting to crash another plane somewhere, “and the gloves were off.” Until that point, C.I.A. and F.B.I. agents were taking turns interrogating Mr. Zubaydah, who had stopped cooperating, in a secret prison that has since been revealed to have been in Thailand.
“C.I.A. was never interested in prosecutions,” Dr. Mitchell said. “The C.I.A. was not going to let them set off another catastrophic attack in the United States. They were going to go right up to the line of what was legal, put their toes on it and lean forward.”
Dr. Mitchell opened what is expected to be two weeks of testimony by telling defense lawyers that the only reason he had come to Guantánamo was to testify in person in front of families of the Sept. 11 victims.
“You folks have been saying untrue and malicious things about me and Dr. Jessen for years,” Dr. Mitchell said, referring to John Bruce Jessen, another psychologist who worked with him to devise the interrogation system. They went on to set up a business that provided guards and interrogators to work at the secret overseas prisons set up after the 2001 attacks and the subsequent invasion of Afghanistan. They received $81 million for the contract.
Had Dr. Mitchell refused to come, the Air Force colonel presiding in the case could have ordered him to testify by video teleconference from Washington.
“I actually did it for the victims and families. Not you,” Dr. Mitchell said under questioning by James G. Connell III, a lawyer for Mr. al-Baluchi. About 12 relatives of victims and their companions were observing the hearing, one wearing a necktie with the Statue of Liberty on it.
They were sequestered behind a blue curtain in the spectator’s gallery of the court, hidden from the troops, journalists, legal observers and court staff also watching what is expected to be the most dramatic testimony so far since arraignment of the five men in the case in May 2012.
Dr. Mitchell, with a full snow-white beard and thinning white hair, wore a charcoal suit to court with a crisp white button-down shirt and a red tie. Mr. Mohammed was in his typical court attire: a green camouflage hunting jacket atop white flowing clothes, a black and silver scarf fashioned into a turban and black orthopedic shoes.
Dr. Mitchell adopted an aggressive approach as a witness. After a prosecutor provided him with a top secret guide to the codes the United States government had assigned to interrogators whose names cannot be used in court, he declared the list flawed. He said it gave a “false and misleading impression that these men were interrogated during their entire time in custody. And they were not.”
He said some of the code-named people identified as interrogators were actually “debriefers, targeters and analysts.”
Drs. Mitchell and Jessen were called to testify by lawyers for Mr. al-Baluchi. But all five defense teams are expected to question them about what went on in the clandestine overseas prisons, including one in Thailand that for a time was run by Gina Haspel, now the C.I.A. director.