WEST BERLIN, OCT. 2 -- With the slam of a gavel on a wooden block, the British commandant in Berlin today ended Allied control of the city.

The four victorious World War II nations had retained far more power over Berlin, capital of the crushed Nazi Third Reich, than over the rest of Germany. But reunification means the end of Allied rights over the once and future German capital, and the U.S., British and French military commanders of the city met for the last time at the ornate Allied Kommandatura headquarters to sign a letter relinquishing their role.

Soldiers lowered the flags of the three Western allies. A fourth flagpole, reserved for the Soviet banner, remained bare, a symbol of the Soviet Union's decision to walk out of the Four Power control commission in 1948, never to return.

Inside the commandants' meeting room, the three generals sat beneath portraits of themselves and the Soviet commandant at the time of the walkout, Gen. Alexander Kotikov. "At midnight tonight, the task of the commandants will be done," said U.S. Maj. Gen. Raymond Haddock. "We three commandants will shortly leave Berlin."

At midnight, legal control of the city was to return to the Germans. No longer would Berlin's mayor have to notify the Allies that he is visiting the eastern part of the city. No longer would the Allies be able to tell Berliners that they cannot carry kitchen knives, float hot-air balloons or send voting representatives to their country's legislature.

The building where the Allied generals met regularly will be returned to the German insurance company from which it was requisitioned 45 years ago.

Today, American, British, French and Soviet soldiers halted their patrols of the city, the so-called "liaison missions" -- essentially spy units in unmarked vehicles -- that continued on both sides of the Berlin Wall even during the height of Cold War tensions. The Soviets quit their watch over the transit corridors, the Western-built highways that connected West Berlin to West Germany.

Although the Soviets skipped today's ceremony at the Kommandatura, they invited Western Allied officers to join their own closing event at the Glienecke Bridge, the crossing point between West Berlin and Potsdam in East Germany where the two superpowers often exchanged spies and other prisoners.

"Nowhere in the world was the confrontation of the superpowers more tangible than in Berlin," the city's two mayors, Walter Momper of the West and Tino Schwerzina of the East, said in a statement. "Like the sword of Damocles, the Soviet threat hung over this city in the '50s. . . . Now Berlin is liberated from the pressure of such confrontation."

The 12,000 Allied troops in the city will remain for a while. The first 700 of the 6,000 U.S. troops in Berlin will leave by March. The last soldiers will leave when the Soviets complete their pullout by the end of 1994.

Long before then, the Allied presence will diminish markedly; diplomats who live in many of Berlin's finest mansions already are packing up. The head of the U.S. Mission, Harry Gilmore, will move to the old U.S. Embassy in East Berlin, which as of midnight will become a branch of the American Embassy in Bonn.

The U.S. Mission in West Berlin will gradually be phased out, and the building, once Nazi Luftwaffe headquarters where Adolf Hitler stood on the balcony to review his troops, will be returned to German control.

With East Germany out of existence, the U.S. ambassador to the country, Richard Barkley, will simply return to Washington.

The Bonn government, which last year paid $1 billion to support the Allied military and diplomatic presence in Berlin, will still pay for the Allied soldiers to remain, but now it is the Germans who will make the rules.

The departure of the Allies is not total. Some of the most important U.S. and British listening posts in the world are located in Berlin, including the top-secret installation atop Teufelsberg, or Devil's Mountain.

"Where else do we get this far inside a country that was so integral to the Warsaw Pact?" an American official said.

Here, at Field Station Berlin, Western intelligence antennae first picked up indications that the Berlin Wall was to be built and that Soviet troops were headed to crush Czechoslovakia's Prague Spring. The facility remains crucial to U.S. intelligence -- as an ear attuned not only to the East, but to the Middle East, officials said.

U.S. sources said the Bonn government had no problem with the Americans retaining their intelligence facilities in Berlin, although many of the 500 telephone monitors the United States employed in the city are expected to lose their jobs.

Hours after the generals signed their letter, the first symbol of German sovereignty, a Lufthansa jet, landed at Berlin's Tegel Airport. For 45 years, no German carrier had been permitted in West Berlin; Pan Am, British Airways and Air France were the only airlines allowed.

Bonn's government has informally told the Allied airlines that they must wind down their Berlin operations within three years. Financially struggling Pan Am took the hint and sold its rights to Lufthansa for $150 million. British Airways considered trying to buy a stake in the East German carrier, Interflug, but eventually soured on the idea.