The last six of about 160 East Germans who occupied the West German Embassy in Prague in a desperate attempt to gain passage to the West finally abandoned their sit-in today and returned home by train.

Their departure from the embassy, which came only one day before an offer of immunity from prosecution by East German authorities was due to expire, climaxed a four-month ordeal that frustrated and embarrassed the governments of both Germanys.

Heinrich Windelen, Bonn's Minister for Inter-German Affairs, expressed great relief that the occupation was over and said he now expected the communist government in East Berlin to relax curbs on exit visas for thousands of East Germans reportedly seeking to leave their country.

He added that those who participated in the occupation would be allowed to go to the West "within a reasonable period."

Nearly 40,000 East Germans were permitted to go to the West last year -- far more than at any other time since the Berlin Wall was built in 1961. But the pace of emigration has slowed drastically in recent months as the East German government emphasized its determination to resolve the siege without bowing to the refugees' demands for guaranteed exit visas.

Wolfgang Vogel, an East Berlin lawyer who acted as a mediator on behalf of East German leader Erich Honecker, announced today that the six remaining East Germans left the Prague embassy "of their own free will" and will apply to emigrate through legal channels in their hometowns. He warned against any emulation of their occupation tactics, saying that immunity would not be granted in the future.

"I warn very solemnly and emphatically against any kind of an attempt at repetition," said Vogel, who has handled most refugee transactions for his government. "No one shall be able to reproach me for not having made this sufficiently clear."

West German officials have repeatedly implored people living in East Germany to refrain from "jumping the exit visa queue" by occupying diplomatic missions. Top ministers in Chancellor Helmut Kohl's government have issued frequent appeals on West German television, which reaches most of East Germany's 17 million citizens, contending that such desperate action not only jeopardizes an orderly emigration flow but also places enormous psychological strain on the delicate ties between the two German governments.

Last year, more than 60 East Germans obtained exit visas by squatting in the U.S. Embassy and the West German diplomatic office in East Berlin until their demands were met.

When guards were posted around legations in East Berlin to thwart further sieges, West Germany's embassy in Prague became a popular haven for East Germans wishing to emigrate without enduring the harassment and long wait often involved in legal applications to leave their country. Czechoslovakia is the only country that East Germans can visit without a visa.

The West German government does not recognize a separate East German nationality, offering a passport and citizenship to all Germans.

In October, the Bonn government shut down its embassy in Prague because the building was completely full and more East Germans were trying to climb over the gates to seek refuge.

West German officials attributed the frenzied rush into the Prague embassy to fears among the East German public that legal emigration channels were about to be closed following the huge exodus allowed early last year.

Moreover, many East Germans believed that Honecker's decision to bow to pressure from Moscow and cancel his planned visit to West Germany last September presaged a renewed chill in relations between the two Germanys.

"There was a strong feeling here at the time that the escape route through West German missions was the last foreseeable chance to get out," a diplomat in East Berlin said.

At the peak of the Prague sit-in, Bonn's embassies in Bucharest, Warsaw and Budapest were also besieged by East Germans and local citizens claiming German origin who demanded the right to emigrate to the West.

About 160 East Germans passed through the Prague embassy during the four-month occupation, but most of them became discouraged and returned home.

By late December, the desperation of those who remained became so acute that 40 of them went on a hunger strike to dramatize their cause. But they ended their fast after two weeks and accepted that they could not get to the West without first returning to East Germany.

West German officials said they do not believe that the difficulties over the sit-in will harm relations between the governments in Bonn and East Berlin.