In a letter from Prague in late 1977, two elderly Americans who had fled the country more than 20 years ago to escape McCarthy era spy charges wrote President Carter to say they wanted to come home.

Alfred K. Stern, 82, and his wife, Martha, who is in her 70s, told the president that they were American refugees who felt isolated in a strange land

The letter was part of a 10-year campaign to get the espionage case against them dismissed. It involved a New York lawyer, a family friend, a California congressman and finally the Justice Department attorneys whose job is to prosecute, not free, subspected spies.

Yesterday, nearly 22 years after they were indicted, the government dropped its case against the Sterns.

"We had a legal and ethical obligation not to hang something over their heads to keep them from coming back," Judith Bartnoff, an associate deputy attorney general who worked on the case, said yesterday.

In papers filed in U.S. District Court in New York City, Justice lawyers noted that several witnesses in the old case had died, including two who were "essential" to the prosecution.

"I don't know if the Sterns were spies or Communists, but with the witnesses dead we had no evidence anyway," Bartnoff said. "The decision to dismiss was the human thing, the proper thing to do."

Victor Rabinowitz, the Sterns' attorney, said yesterday that he'd been pleading his client's cause before the Justice Department "every few years or so" for the past decade.

Then, a few years ago, he said, he found a sympathetic ear in then deputy attorney general Harold Tyler. Interest in the Stern case picked up in the Carter administration, and was pushed, since mid-1977, by Rep. Don Edwards (D-Calif.).

"I've been battling this kind of thing for a long time," Edwards said yesterday. "I got rid of the House Un-american Activities Committee in the Democratic Caucus a few years ago.

"You didn't have to have much evidence to get an indictment in the McCarthy days."

The Sterns, who were called "multimillionaires" in newspaper stories about the September 1957 indictment, had left the United States for Mexico in 1953 after being fingered as Soviet spies in HUAC testimony and refusing to appear before a New York grand jury.

Boris Morros, a movie producer who was a government informer, said Stern advanced him more thatn $100,000 to bankroll a business that was a Soviet espionage front.

Edwards said his research into the case showed Morros, who has since died, to be of "doubtful integrity."

It took more than a year and a half to review the Stern case, officials said yesterday, because the FBI was reluctant to let them come back to the United States without undergoing a 10-hour interrogation first. Finally, in recent weeks the internal security lawyers at Justice decided that the death of witnesses made the ancient case untriable, and the dismissal was approved.

Sylvia Crane, of New York City, a family friend of the Sterns who interested Edwards in their case, said last night that she had just talked to the couple in Prague. "They were over-joyed, of course," she said.

"The persecution of the Sterns was part of a McCarthy dirty tricks campaign. They always have had great faith in this country," Crane said.

In August 1957 a biting Scripps-Howard story said, "Government spy hunters were convinced today that the new No. 1 mystery woman in the Communist espionage conspiracy, Martha Dodd Stern, will never return to America."

Despite their emotional plea in the letter to Carter and the successful outcome of their case, there is a possibility that the Sterns may not return to their homeland, Crane said.

"They don't know if they can live here as well," she said. "They're a bit worried about inflation."