At one point, the prosecutor, Michael Farbiarz, told the judge that although Russian officials had met with the defendants, they had done nothing to force them to plead guilty or entice them into doing so. Defense lawyers concurred.

One lawyer, though, John M. Rodriguez, said Russian officials had made promises to his client, Ms. Peláez, but he assured the judge that they were not inducements to make her plead guilty. He said Ms. Peláez was told that upon her arrival in Russia, she could go to Peru or anywhere else; she was promised free housing in Russia and a monthly stipend of $2,000 for life and visas for her two children.

Ms. Peláez was not formally trained as a spy, her lawyer has said. He has also said that she had no desire to go to Russia as part of a swap. “I know we were the last to sign” a plea agreement, Mr. Rodriguez said after the hearing on Thursday.

The defendants included several married couples with children. American officials said after the court hearing that they would be free to leave the United States with their parents.

Perhaps the most recognizable of the agents was Ms. Chapman, who ran her own real estate firm and who had attained a degree of notoriety after tabloid newspapers worldwide chronicled her sex life and reprinted photographs of her in skimpy attire.

Administration officials who insisted on the condition of anonymity to discuss the delicate decision would not say who initially proposed a swap but added that they considered it a fruitful idea because they saw “no significant national security benefits from their continued incarceration,” as one put it. Some of the four Russians to be freed are in ill health, the official added.

Another American official, who was not authorized to speak about the case, said officials of the intelligence agencies were the channel for most of the negotiations, particularly Leon E. Panetta, the director of the C.I.A., and Mikhail Y. Fradkov, director of the S.V.R., Russia’s foreign intelligence agency.