On Jan. 10, two members of Congress with a strong interest in Soviet Jewry, Reps. Benjamin A. Gilman (R-N.Y.) and Tom Lantos (D-Calif.), visited the East Berlin home of Wolfgang Vogel, an East German lawyer who has arranged several prisoner exchanges between East and West over two decades.

They were seeking information about the status of Anatoly Scharansky, the Jewish dissident who had been imprisoned by the Soviet Union since 1978 as an alleged American spy. Vogel surprised the congressmen by replying that he had been given a "mandate" by the East German and Soviet governments to arrange Scharansky's release as part of an impending swap of West German and East German prisoners.

It was, as Gilman recalled later, "the first hard signal" that an intensive and highly secret campaign to win Scharansky's release, set in motion by the Reagan administration more than a year earlier, would succeed. It ended happily early yesterday when Scharansky walked from the East Berlin suburb of Potsdam across the Glienicke Bridge into the freedom of West Berlin.

For those involved in the effort, the period between the meeting with Vogel and Scharansky's release was a time of unrelieved suspense, punctuated by other encouraging signals from the East bloc and fears that leaks could cause Soviet officials to change their minds.

On Jan. 16, Lawrence Horowitz, administrative assistant to Sen. Edward M. Kennedy (D-Mass.) went to Moscow to negotiate the terms of a Kennedy visit. He was told by Soviet officials that the Supreme Soviet had made "a final decision" to send Scharansky to the West within 60 days. But Horowitz also was warned sternly that the decision would be rescinded if it was disclosed to the western press.

Kennedy, acting partly on that assurance, began his trip to Moscow on Jan. 27. While still in the air, he received word that a West German newspaper, Bild, had published a report that Scharansky would be swapped Feb. 11. As a result, his first order of business after arriving in Moscow was to ascertain whether the Soviets intended to make good on the threat to Horowitz by canceling the swap.

Kennedy's concern was quickly allayed by Soviet officials, including Foreign Minister Eduard Shevardnadze. According to sources familiar with their meeting, Shevardnadze told him: "Senator, we are aware that you have been pressing this case for several years. I want to assure you that this case will be disposed of."

These incidents were described by various U.S. officials, diplomatic and congressional sources and others familiar with the complex chain of events leading to Scharansky's release. Collectively, their accounts present a picture of lengthy, slogging, secret negotiations that overcame innumerable false starts and threats of failure before ending successfully.

While such figures as Kennedy, Gilman and Lantos played important roles in the latter stages as conduits for the signals from the East, those involved are unanimous in declaring that the principal credit belongs to President Reagan and Secretary of State George P. Shultz, who laid out the basic policy premises, to a small group of senior American diplomats who worked behind the scenes to implement their orders and to West German Chancellor Helmut Kohl's government, which provided the cooperation on which the success of the effort hinged.

"The president and Shultz have been criticized frequently for their insistence on seeking to use quiet diplomacy to make progress in human rights," Gilman said. "But in this case, at least, they achieved a result that would not have been possible if they had raised the issue in a public, confrontational manner."

As described by the sources, the origins of the story go back to late 1984 when the administration was seeking ways to improve relations with the Soviet Union. As part of its attempt to gauge the sincerity of Soviet intentions, the administration adopted the tactic of using every encounter between U.S. and Soviet officials to raise American concern over the plight of the Soviet Union's two most prominent dissidents, Scharansky and Nobel Peace laureate Andrei Sakharov.

"We did not miss an opportunity, whether in a meeting between Shultz and the Soviet foreign minister or in lower-level encounters, to make clear that these were matters of major concern to the administration and to the American people," one official said. "We left them in no doubt that we would regard their treatment of Scharansky and Sakharov as a key test of their desire for improved relations."

In the case of Sakharov, the Soviets proved unyielding -- a stubbornness reiterated last week when Soviet leader Mikhail Gorbachev said in an interview that the dissident physicist has knowledge of state secrets and "for this reason cannot go abroad."

Initially, the Soviets were similarly inflexible about Scharansky, insisting that he was a spy whose fate was a purely internal Soviet matter. However, after Gorbachev came to power last March with an obvious interest in improving the Soviet image abroad, the United States began to receive hints that Moscow might be willing to resolve the Scharansky issue.

A turning point occurred last June 11 when the United States traded one accused and three convicted East bloc spies for 23 prisoners held in East German and Polish jails. The exchange, which was the largest East-West swap of its kind in Europe, also took place at Berlin's Glienicke Bridge and was arranged by Vogel, a confidant of East German leader Erich Honecker, and Richard R. Burt, who was then winding up an assignment as assistant secretary of state for European affairs and preparing to become U.S. ambassador in West Germany.

At a dinner that night in East Berlin's Palast Hotel, Burt stressed to Vogel the importance that Washington attached to the Scharansky case, and the attorney agreed to explore what might be done. He noted, though, that because Scharansky had been convicted of espionage, the Soviets would insist that he could only be released as part of a spy swap.

That posed a problem for the United States because it had surrendered all the major espionage agents held in American jails in the June 11 swap and, as one U.S. official put it, "Our cupboard was bare." The United States turned to Kohl's Bonn government, and the chancellor agreed to consider trading prisoners held by West Germany and sought by the Soviets and their allies.

Secret negotiations began in earnest after Burt moved to Bonn in September. They were conducted largely through Vogel. West Germany was represented by Ludwig Rehlinger, Kohl's minister for relations with East Germany. On the U.S. side, the main burden was carried by Burt and Francis J. Meehan, the U.S. ambassador in East Germany, with the effort coordinated here by R. Mark Palmer, the State Department's senior specialist on Soviet and East European affairs, and John F. Matlock, his opposite number on the National Security Council staff.

The decision last summer to hold a Gorbachev-Reagan summit in Geneva provided a powerful spur to the talks. The Soviets, apparently seeking to make a dramatic gesture in advance of the summit, showed increasing flexibility, and by October it appeared that a spy swap agreement including Scharansky was imminent.

That deal collapsed at the last minute, apparently because of an unexpected Soviet demand that the exchange include a prisoner whom Bonn was unwilling to release. The sources did not identify the disputed prisoner. He may have been Manfred Rotsch, who is awaiting trial in West Germany on charges of spying for Moscow, or Lothar Lutze, who is serving a 12-year sentence for stealing North Atlantic Treaty Organization secrets for East Germany.

At the Geneva summit in November, Reagan raised the Scharansky issue anew with Gorbachev; it was discussed in greater detail by their subordinates during the summit. In late November, Vogel made a new approach to Rehlinger and U.S. officials, saying that he had a new authorization to act for both the East Germans and the Soviets in finding a new mix of prisoners whose exchange would be agreeable to both sides.

There followed intensive new negotiations where, as one U.S. source said, "various names were dropped in and out." Looking back at these events, the sources speculated that the Soviets decided sometime in December to strike a deal that would permit the release of Scharansky.

They noted that Scharansky was allowed to send a 30-page letter received in Moscow by his brother, Leonid, on Jan. 6. Anatoly Scharansky wrote that he had been moved to a hospital where he was receiving better food and treatment. The sources said the move had to have been made around late December or early January and appeared to have been intended to "fatten him up and get him in better shape" prior to release.

That impression was reinforced by the signals that were given to Gilman and Lantos in East Berlin and to Kennedy in Moscow. At any rate, the sources said, by early this month, the negotiations on which prisoners to exchange had narrowed down to a list acceptable to Bonn and East Berlin. To sweeten the deal, the United States also agreed to throw into the exchange Karl F. Koecher, a Czechoslovakian emigre awaiting trial here on charges of spying for his homeland.

The sources acknowledged that publication of the Bild article in late January -- attributed by the paper to "high Soviet sources" -- raised concern that the Soviets might abort the budding deal. Even Scharansky's wife, Avital, who flew here from her home in Israel for a meeting with Kennedy's staff just before the senator went to Moscow, expressed fear that the Soviets would leak the story deliberately to provide an excuse for backing out of the deal.

Despite the assurances given to Kennedy by Shevardnadze that the matter would proceed, U.S. officials said that the Soviets, citing the public attention that Bild had focused on the Feb. 11 date, argued that the exchange should be moved from the Glienicke Bridge to a secret new location.

The United States expressed reluctance to change the venue, and the Soviets agreed to keep the original site. It was there that Scharansky finally came over to the West yesterday to be greeted by Burt and whisked off to begin the trip to a new life in Israel.

Some American Jewish organizations suggested that Reagan should have sent a special representative to Israel to greet Scharansky on his arrival there on behalf of the United States. But the State Department, sticking to its insistence on quiet diplomacy, vetoed the idea.

"We are interested in results, not cosmetics," one department official said. "Sakharov is still in the Soviet Union. Others not as well known are still there. Our efforts to help them wouldn't be advanced by sticking a finger in Moscow's eye."