Poland and Germany Wednesday formally settled one of the last disputes of World War II, signing a treaty confirming their long-questioned border on the Oder and Neisse rivers.

In the pact, Germany abandons claim to 40,000 square miles of its former territory in East Prussia, Pomerania and Silesia that was added to Poland after the war. The land Poland gained from Germany made up for a greater expanse of land in the east taken from Poland by the Soviet Union.The formerly German lands account for about one-third of Poland today.

The treaty commits the countries to building "a peaceful European order, in which borders will not divide and which . . . will ensure permanent peace, freedom and stability."

The pact was signed by Foreign Ministers Hans-Dietrich Genscher of Germany and Krzysztof Skubiszewski of Poland at the Council of Ministers building, seat of the Polish government.

Skubiszewski said "both nations should congratulate themselves" for closing a difficult chapter in their histories.

Genscher said the loss of German lands confirmed by the pact was the fault of the "criminal system" in Germany during World War II.

He said the pact shows the newly united Germany's will to establish a firm basis of friendship with Poland.

Polish Prime Minister Tadeusz Mazowiecki made what appeared to be Poland's strongest statement of apology to the Germans for the loss of their lands.

"We ask for forgiveness," he said. "The suffering of the German nation must be spoken about. . . . Every harm remains a harm, every tragedy remains a tragedy, irrespective of the harms and tragedies that we ourselves experienced."