The Soviet Union, in a 1979 deal worked out with top aides of president Carter, agreed not to execute a spy condemned to death after being caught working for the United States in Russia.

The revelation that the Soviets "also agreed not to execute . . . one of our spies who had been condemned to die," is included in the just-published memoirs of the former president as an entry in his diary on April 26, 1979.

Carter discloses that the heretofore secret American attempt to save the life of the unidentified spy was part of a larger negotiation in which the administration arranged for five imprisoned Soviet dissidents to leave the Soviet Union. In return, the United States sent back to Moscow two Soviet employes of the United Nations in New York, who were convicted here of espionage.

The swap involving the Soviet dissidents and what Carter, in his memoirs, calls the "two United Nations minor spies" was rather widely publicized at the time. The portion involving the spy for the United States, presumably a Russian who was caught in the Soviet Union, was not made public here.

When asked about the comment in Carter's new book, "Keeping Faith," two former senior officials in his administration expressed the view that the ex-president had committed an "indiscretion," as one put it, by revealing this.

The negotiations over the fate of the spy were conducted in private between former Carter national security adviser Zbigniew Brzezinski and his deputy, David L. Aaron, and Soviet ambassador to the United States, Anatoliy F. Dobrynin. A condition of those talks, officials said, was that they would not be made public.

Other officials said it is unusual for an American president to voluntarily acknowledge that there are American spies inside the Soviet Union.

The prospect that an important spy working for the United States in the Soviet Union had been inadvertently compromised and arrested became the subject of allegations in some news media during the election campaign of 1980.

The allegations centered on claims that Aaron had engaged in some loose talk at a diplomatic gathering which ultimately exposed the spy in the Kremlin.

On Oct. 2, 1980, columnist Jack Anderson reported that "Aaron's slip allegedly exposed the identity of Anatoly N. Filatov, a Soviet intelligence officer who worked undercover as an American agent known to the CIA by the code name Trigon."

Anderson noted that the Soviet press reported he had been executed but that Filatov's lawyer claimed he was still alive, serving a 15-year sentence.

At the time, the White House strongly denied that Aaron had any role in whatever had happened in Moscow, and the Senate Intelligence Committee reported in December 1980 that it had found no evidence to support allegations that Aaron had accidentally exposed the spy.

Several Carter administration officials contacted yesterday, including Brzezinski, Aaron and ex-CIA director Stansfield Turner, declined to comment on the spy's identity and would not confirm it was Filatov.

Aaron, in a telephone interview, said, "Obviously, the president knows what he is talking about. There is a rather substantial irony," Aaron said, "that while I was accused of being this guy's demise, in fact we were working successfully to save his life."

This appeared to be an indirect confirmation that Filatov was the spy, although Aaron declined to say to whom Carter was referring.

Another former top intelligence official said that Aaron "did talk too much" but that he was not responsible for compromising the spy.

He said some people had "put two and two together," meaning reports of the spy arrest and reports about Aaron, "and come up with nine."

This official said a number of things were happening at the same time and he is not certain if the spy being referred to by Carter was indeed Filatov.

Another former intelligence official, however, who could not recall all the details of the case, said it was his impression the administration was indeed trying to save the life of somebody they had inadvertently compromised.

Brzezinski said in a telephone interview that "whoever the Soviet was, our interest in saving his life had nothing to do with the false allegations involving Aaron."