WARSAW, NOV. 14 -- The last major dispute of World War II was formally settled here today as Poland and Germany signed a treaty fixing their mutual border on the Oder and Neisse rivers.

The treaty affirms Poland's right to 40,000 square miles of land that was cut out of eastern Germany and awarded to this country following the war.

"The decision we are making with the treaty signed today is no easy one for us Germans, for any of us -- including myself," German Foreign Minister Hans-Dietrich Genscher said. "For those who have lost their homelands, who suffered expulsion, it is an especially painful one."

Millions of Germans were expelled from the territory, which makes up about one-third of present-day Poland. Until the unification of Germany, conservative German politicians, including Chancellor Helmut Kohl, had been ambiguous about their willingness to relinquish all claim to the land.

A major reason for that ambiguity was the political muscle of the well-organized expellees who settled in western Germany and their descendants. They still insist that the land is German.

Genscher, however, said bluntly today that "we Germans are aware that the treaty does not surrender anything that was not lost long ago as the result of a criminal war and a criminal system. We recall the suffering of the Polish people under German occupation."

One in five Poles was killed during the Nazi occupation, a higher per capita death toll than in any other nation, and Poles remain profoundly suspicious of Germans, especially since the collapse of Communist East Germany and German reunification.

The treaty's guarantee that the present border is "inviolable" marks a major foreign policy and political victory for the government of Prime Minister Tadeusz Mazowiecki. His government this year made "the German problem" one of its priorities.

The signing is expected to boost Mazowiecki's uphill race against Solidarity union leader Lech Walesa for the presidency in an election Nov. 25. By agreeing to sign the treaty at the height of the race, it appears that the German government was trying to help Mazowiecki.

Kohl also has promised to ease visa requirements for Poles by Christmas, a move that, in effect, gives Poles unrestricted access to much of Western Europe.

In another apparent election-timed nod to Mazowiecki, German Labor Minister Norbert Bluem announced Tuesday that Poles living near the border will be able to work permanently in Germany, if they go home at night. He also said all Poles, as well as Czechoslovaks, will be allowed to work in Germany for up to three months a year.

The consistent free-market policies of Mazowiecki's government have been widely praised in Bonn and throughout Western Europe. The policies that might come out of a Walesa presidency, on the other hand, are viewed as much less predictable. Walesa has been more willing than Mazowiecki to make vague campaign promises about how the pain of free-market reform need not be borne by workers.

Mazowiecki, who assembled his entire cabinet for the nationally televised signing of the treaty, used the ceremony to make a speech that emphasized how his leadership is enabling Poland to "close the chapter of the past and look into the future."

Final agreement on the treaty was reached last week in a meeting between Mazowiecki and Kohl at the German-Polish border.

"We believe that on the road to Europe we shall meet with kind, helpful attention of the democratic Germany," the prime minister said.

He also apologized for Polish behavior in the aftermath of World War II. In that period, several million Poles were transferred from eastern lands seized by the Soviet Union to the western lands taken from Germany. German property was stolen, and ethnic Germans were driven from their ancestral land.

"One has also to speak about the suffering of the German nation that resulted from the movement of Poland from the east to the west," Mazowiecki said. "We ask for forgiveness."