GUANTÁNAMO BAY, Cuba — After 183 rounds of waterboarding, Khalid Shaikh Mohammed, the man accused of plotting the Sept. 11, 2001, attacks, spent his years in C.I.A. detention as a charming captive who dabbled in Islamic mysticism and engaged in pleasantries with the psychologist who waterboarded him, that psychologist told a war crimes prosecutor on Thursday.
James E. Mitchell, who as a contractor for the C.I.A. helped develop the agency's interrogation program and handled all the waterboarding, said Mr. Mohammed managed so well in his last three years in the secret prisons after the violent questioning had ended that the two men would sit and hold hands, as Middle Eastern men sometimes do.
He said Mr. Mohammed put on a "charm initiative" and described him as a well-adjusted detainee who never expressed fear of him, gave the psychologist a nickname, "Abu Captain," and sought his help in improving his conditions as he was moved through the different C.I.A. black sites.
Mr. Mohammed's lawyer rejected Dr. Mitchell's account, saying his client was motivated by fear in dealing with the psychologist.
Dr. Mitchell offered his description in response to questioning by a prosecutor, Jeffrey D. Groharing. Dr. Mitchell said that he had assessed Mr. Mohammed and four other men accused of conspiring in the 9/11 attacks to be of sound mind when he saw them in the black sites.
Dr. Mitchell described visiting the sites, where his contracting firm provided the guards, and said he detected no signs of flashbacks, nightmares or apathy by the five men, who are scheduled to go to trial on Jan. 11, 2021. Defense lawyers sought Dr. Mitchell's testimony to help the judge decide whether the men were tortured and whether answers they gave to F.B.I. agents several months after their transfer to Guantánamo in 2006 were voluntary. Involuntary admissions are forbidden in war crimes trials.
For eight days, defense lawyers used C.I.A. cables from the black sites to question Dr. Mitchell about the interrogation program he designed to pressure Qaeda suspects to answer C.I.A. questions by using waterboarding, sleep deprivation and methods known as short-shackling and walling.
The lawyer for one defendant, Walid bin Attash, who was captured with a prosthetic leg from a war wound, showed on Thursday C.I.A. cables describing his client as being kept nude and shackled standing on his only leg during a long stretch of sleep deprivation. It included a C.I.A. medical officer's measurements of the swelling of his foot, ankle and calf.
Dr. Mitchell said he never saw the man during that period. In response to the prosecutor, he testified that Mr. bin Attash was a well-adjusted, proud warrior when he caught up with him later.
Mr. bin Attash said that before the Sept. 11 attacks, he helped blow up the Great Buddhas of Bamiyan in Afghanistan, a World Heritage site, Dr. Mitchell said.
At issue in the pretrial proceedings is whether the defendants were so thoroughly damaged by torture when they arrived at Guantánamo in 2006 that they were helpless to do anything but tell F.B.I. agents what they wanted to hear.
Dr. Mitchell and his partner, John Bruce Jessen, designed and carried out the interrogation program. While he was held in a secret C.I.A. prison in Poland in March 2003, Mr. Mohammed was waterboarded, deprived of sleep and had his head slammed against a wall.
Dr. Mitchell explained the program this way: Once the C.I.A. prisoners understood that resistance would be met with violence, they cooperated across subsequent years of questioning.
So much so, Dr. Mitchell said, that for a time before the defendants were sent to Guantánamo, they were assembled at a single C.I.A. black site in isolation and unaware that the others were there. Interrogators could visit each cell with the same photograph for identification.
Dr. Mitchell said he called the place T3, for Terrorist Think Tank.
He described the aim of the interrogations and debriefings as getting raw intelligence about impending plots and Qaeda associates for intelligence rather than prosecutorial purposes.
Mr. Mohammed, Dr. Mitchell said, volunteered before he was waterboarded — but after he was brutally interrogated in Afghanistan — that he was responsible for the Sept. 11 attacks that killed 2,976 people in New York, Pennsylvania and at the Pentagon.
With Mr. Mohammed sitting impassively in court, his lawyer, David Nevin, reeled off a series of actions that his client associated with Dr. Mitchell: taking custody of him soon after rectal abuse, waterboarding him and threatening to kill his child. Mr. Nevin suggested that Mr. Mohammed was nice to Dr. Mitchell because he was afraid of him.
"He never once complained to me about my relationship with him," Dr. Mitchell said. "I brought him as many good things as bad things. That disrupts that kind of classical conditioning."
As an example, Dr. Mitchell said that when Mr. Mohammed became interested in Sufism, a form of Islamic mysticism, the psychologist intervened with the C.I.A. to let him set hours for his debriefings that did not disrupt his prayers, by letting him hang an "open" sign on his cell.
Dr. Mitchell also said that to distract his debriefers from their pursuit of ongoing plots, Mr. Mohammed said that he had personally beheaded the Wall Street Journal reporter Daniel Pearl, who was kidnapped in Karachi, Pakistan, on Jan. 23, 2002. Mr. Mohammed invited investigators to compare his hairy arm to the one in an internet video of the beheading. He has not been charged in the killing.