Aides said Mr. Obama struggled for four weeks about whether to release the memos in response to a lawsuit filed under the Freedom of Information Act, consulting with advisers, experts and intelligence professionals. It was on his mind so much, they said, that he talked about it with aides late at night in his hotel room during stops on his recent European trip.

Image President Obama, in a visit to C.I.A. headquarters on Monday, said employees of the agency would not be prosecuted for taking part in harsh interrogations. Credit... Jim Wilson/The New York Times

In meetings, they said, he served as “the interrogator,” as one put it, challenging people to defend their views. Advisers diverged, with some like Attorney General Eric H. Holder Jr. favoring the release of more information and others like Leon E. Panetta, the new C.I.A. director, urging that more be withheld. Aides said Mr. Obama worried about damaging morale at the C.I.A. and his own relationship with the agency.

In the end, aides said, Mr. Obama opted to disclose the memos because his lawyers worried that they had a weak case for withholding them and because much of the information had already been made public in The New York Review of Books, in a memoir by George J. Tenet, the former C.I.A. director, and even in a 2006 speech by President George W. Bush.

The decision to promise no prosecution of those who followed the legal advice of the Bush administration lawyers was easier, aides said, because it would be hard to charge someone for doing something the administration had determined was legal. The lawyers, however, are another story.

On Sunday, Rahm Emanuel, the White House chief of staff, said on the ABC News program “This Week” that “those who devised policy” also “should not be prosecuted.” But administration officials said Monday that Mr. Emanuel had meant the officials who ordered the policies carried out, not the lawyers who provided the legal rationale.

Three Bush administration lawyers who signed memos, John C. Yoo, Jay S. Bybee and Steven G. Bradbury, are the subjects of a coming report by the Justice Department’s ethics office that officials say is sharply critical of their work. The ethics office has the power to recommend disbarment or other professional penalties or, less likely, to refer cases for criminal prosecution.

The administration has also not ruled out prosecuting anyone who exceeded the legal guidelines, and officials have discussed appointing a special prosecutor. One option might be giving the job to John H. Durham, a federal prosecutor who has spent 15 months investigating the C.I.A.’s destruction of videotapes of harsh interrogations.