GUANTÁNAMO BAY, Cuba — When the C.I.A. strapped down Khalid Shaikh Mohammed at a secret site in Poland in 2003, those inside the cell included a three-man waterboarding team, black-masked guards — and a doctor.
The doctor's stated role was to monitor the health of the detainee. He also kept count of each near drowning.
"Literally, the physician had a little silver thing," James E. Mitchell, one of the architects of the interrogation program, testified last week to the military tribunal at Guantánamo Bay. The doctor, he said, "would click how many times the water was poured" as a guard kept time with a stopwatch.
But the C.I.A. doctors did more than count waterboarding sessions. Government investigations and evidence in the pretrial hearings of the men, including Mr. Mohammed, accused of conspiring in the Sept. 11, 2001, attacks, show doctors conducted "rectal rehydration," carried out rectal cavity searches and examined swollen feet and legs of captives who were sleep deprived for days by being shackled in painful positions.
Here at Guantánamo, where the judge is hearing testimony in a pretrial hearing to decide, among other things, whether the defendants in the Sept. 11 case were tortured, the proceedings are also putting a spotlight on the role of doctors who worked as medical officers in the intelligence agency's overseas prison program.
"The physicians were present in interrogations that were harmful and life-threatening, and that violates the first principle of medical ethics: First, do no harm," said Stephen N. Xenakis, a psychiatrist and retired Army general, who described himself as shaken by the testimony about the doctor with the counter-clicker. He was sitting in court as a consultant to some of the defense lawyers.
Dr. Xenakis said the role of the C.I.A. doctors in the program was meant "to protect people and keep them safe," not participate in the interrogations.
During testimony Monday, Dr. Mitchell said a "board-certified physician" was in the room for every session of waterboarding and monitored Mr. Mohammed's oxygen saturation level through a device on his finger, a pulse oximeter. Dr. Mitchell said he held a torn T-shirt over the prisoner's nose and mouth for each one of the 183 instances of waterboarding, all carried out by him and his partner in developing the C.I.A.'s interrogation program, John Bruce Jessen.
Dr. Mitchell first offered his description of the C.I.A. doctor with the clicker last week, as a defense lawyer showed him a report from March 2003 describing Mr. Mohammed's 15th waterboarding session. Mr. Mohammed had been sleep deprived more than six days, according to a C.I.A. report. Twelve liters of water was poured in "water applications of two of less than 5 seconds, two of 10, three of 15, one of 20, one of 25 and one of 40," the report said.
During waterboarding, the doctor also "required that saline be alternated with water, to avoid water intoxication," the agency's chief of medical services wrote in 2007 in an anonymous account that was declassified in 2018. "He repeatedly re-examined K.S.M. throughout this period and was struck by how well K.S.M. had withstood the experience."
Partially redacted guidelines from the C.I.A.'s Office of Medical Services dated December 2004 showed the agency required that a physician assistant be present at "enhanced interrogations" except during waterboarding. Then, an actual physician was required to be on site, in case of respiratory arrest or other complications.
That is apparently what happened in August 2002 when Drs. Mitchell and Jessen were waterboarding a prisoner known as Abu Zubaydah, for whom they designed the violent interrogation program.
Mr. Zubaydah lost consciousness during a waterboarding "with bubbles rising through his open, full mouth," according to a declassified portion of a study of the C.I.A. program by the Senate Intelligence Committee.
Drs. Mitchell and Jessen, who are psychologists rather than medical doctors, handled it on their own, the report said, with "medical folks edging toward the room."
None of the medical officers have been identified publicly. The C.I.A. has repeatedly defended its use of rectal rehydration as legitimate medical practice, rather than punishment.
But one graphic episode, read into the court record by a prosecutor in the Sept. 11 case in late 2018, showed the procedure as integrated into an interrogation of Mr. Mohammed in Afghanistan in March 2003, before his transfer to Poland.
An interrogator trying to train Mr. Mohammed to cooperate with him ordered Mr. Mohammed to drink a glass of water. He twice refused, so the prisoner was taken to another room, "placed on a plastic sheet" and a "medical officer rehydrated Mohammad rectally."
Mr. Mohammed "clearly hated the procedure," according to the account. "When he was returned to the interrogation room, he then complied and drank water."
After the use of rectal rehydration and rectal feeding by the C.I.A. was made public, the group Physicians for Human Rights condemned it as "sexual assault masquerading as medical treatment."
At last week's hearings, Dr. Mitchell described the interrogator who ordered the man to drink as the C.I.A.'s chief of interrogations — an agency employee who subsequently died of a heart attack — and the location of the episode as a C.I.A. prison with the code name Cobalt. It is also known as the Salt Pit and was in Afghanistan.
Dr. Mitchell testified on Monday that he did not know about the practice of rectal rehydration and feeding while he was working in the black sites as a C.I.A. contract interrogator and psychologist, and thought it was "a lie" when he heard about it years later.
The agency defended the practice in 2013.
"Medical personnel who administered rectal rehydration did not do so as an interrogation technique or as a means to degrade a detainee but, instead, utilized the well-acknowledged medical technique to address pressing health issues," it said in a once-secret, lengthy protest to the Senate Intelligence Committee.
Dr. Mitchell testified that he visited the Cobalt prison once, in 2002, and reported that the chief of interrogations was behaving more brutally than the agency authorized for interrogations.
In one instance, Dr. Mitchell testified, he and Dr. Jessen sought medical care for a prisoner at Cobalt who would later die in detention, probably of hypothermia, and were rebuffed by a physician assistant in charge of medical care, who replied that he did not care for "terrorists."
The C.I.A. has acknowledged other roles by its medical staff during interrogations, including measuring the swelling of a prisoner's leg during sleep deprivation, monitoring the breathing of hooded prisoners during rendition flights and conducting anal cavity checks in prisoners as they left and arrived at the sites where they were held.
In his 2007 account, the chief of medical services for the C.I.A. also acknowledged that, during "enhanced interrogations," medical providers did not seek knowing consent of the shackled and at times hooded detainee.