The seal of the Central Intelligence Agency at CIA headquarters in Langley, Va. (Carolyn Kaster/AP)

Two psychologists who devised the CIA’s brutal interrogation program have settled a lawsuit with several victims less than three weeks before a jury trial was set to begin in a federal court in Spokane, Wash.

The settlement, reached Wednesday, caps a remarkable case in which for the first time former top CIA officials were forced to testify about their roles in the program launched after the Sept. 11, 2001, attacks. The case unearthed CIA records that shed new light on the program’s creation and how controversial it was within the agency.

In the settlement, the psychologists James Mitchell and Bruce Jessen, who were hired as contractors, acknowledged that they worked with the CIA to develop the program to interrogate detainees using “specific coercive methods.”

But in statements Thursday, the two men distanced themselves from any “unauthorized” actions that spurred the lawsuit.

The terms of the settlement were kept confidential.

The three detainees who were alleged in the suit to be victims of torture were held at a secret prison in Afghanistan known as “the Salt Pit.” One of them, an Afghan named Gul Rahman, froze to death in November 2002. The other two were Suleiman Abdullah Salim, a Tanzanian fisherman arrested in Kenya, and Mohamed Ahmed Ben Soud, a Libyan captured in Pakistan.

All three were subjected to methods developed by Jessen and Mitchell. Rahman was sleep-deprived and kept clothed in only a diaper for almost the entire time Jessen interrogated him, according to information obtained through discovery.

None of the three men was ever charged with a crime by the U.S. government. They endured beatings, various forms of water torture, exposure to extreme temperatures, confinement in stress positions designed to keep them awake for days at a time, and earsplitting levels of music.

“This is a historic victory for our clients and the rule of law,” said Dror Ladin, an attorney with the American Civil Liberties Union, which brought the case on behalf of the victims. “This outcome shows that there are consequences for torture and that survivors can and will hold those responsible for torture accountable. It is a clear warning for anyone who thinks they can torture with impunity.”

In a joint statement, Salim, Soud and the family of Rahman said: “We brought this case seeking accountability and to help ensure that no one else has to endure torture and abuse, and we feel that we have achieved our goals.”

The psychologists made $1,800 a day and later formed a company that was paid $81 million before the CIA cut ties with them. Under an indemnification contract, the CIA is obligated to pay the company’s legal expenses until 2021.

In a statement, Mitchell said: “In the aftermath of 9/11, almost sixteen years ago now, Dr. Jessen and I were asked to serve our country following the most vicious attack on American soil in our history. I am confident that our efforts were necessary, legal and helped save countless lives. However, in an effort to find those terrorists and stop another attack on America, certain individuals performed acts on detainees, including plaintiffs, without our knowledge or consent, and without authorization from the CIA — acts that should not have occurred and for which we are not responsible.”

Jessen said: “Neither Dr. Mitchell nor I knew about, condoned, participated in, or sanctioned the unauthorized actions that formed the basis for this lawsuit. We served our country at a time when freedom and safety hung in the balance. The actions that we actually participated in were legal and authorized and protected our country from another vicious attack.”

The suit was filed in October 2015 using information in a Senate Intelligence Committee report on the CIA’s program, which was published in December 2014, and disclosures from previous ACLU lawsuits.

It was the first CIA torture-related case that was not dismissed at an early stage after government lawyers argued that litigation would reveal state secrets. The Spokane judge repeatedly rebuffed defendants’ attempts to dismiss the case, ruling that the plaintiffs had valid claims.

The case made clear “that the courts are fully capable of handling lawsuits involving grave abuses committed in the name of national security,” said Hina Shamsi, director of the ACLU National Security Project.