In what is being viewed as a major blow to Soviet intelligence, the British government announced today the defection of the top KGB officer in the Soviet Embassy here and ordered the expulsion of 25 Soviet officials identified as spies by the defector.

A Foreign Office statement named the defector as Oleg A. Gordievski, the London station chief for the KGB, the Soviet secret police. The alleged spies, who have been given three weeks to leave Britain, include six accredited diplomats as well as Soviet businessmen, journalists and representatives of international organizations.

Both U.S. and British officials described Gordievski's defection as a major intelligence coup following a series of embarrassing spy scandals recently in both the United States and West Germany.

The Foreign Office statement said that Gordievski had told British agents that he wanted to defect because "he wishes to become a citizen of a democratic country and live in a free society."

According to reports from Denmark, which could not be confirmed officially here, Gordievski might have been working for the West as a double agent for as long as 10 years. In Washington, however, the chairman of the Senate Intelligence Committee said that as far as he knew, the defector had "no past relationship" with western intelligence. Details on Page A33.

Describing the expulsions as "an act of national security," the Foreign Office statement said that Britain still attaches "great importance to the development of a realistic dialogue with the Soviet Union, which can contribute to mutual confidence between East and West." It said the British government would take "an extremely serious view" of any retaliatory expulsion of British personnel in Moscow.

The expulsion of alleged KGB officials from Britain is likely to embarrass Soviet leader Mikhail Gorbachev during the diplomatic buildup to his meeting with President Reagan in November. The Kremlin has launched a propaganda offensive designed to persuade public opinion in Western Europe that Washington poses a much greater threat to world peace than Moscow.

It was the biggest single expulsion of Soviet officials from London since 1971, when 105 alleged spies were thrown out by the government. Earlier this year, five other alleged Soviet spies were expelled.

But while the mass uncovering of Soviet spies is certainly extremely irritating for Moscow and a major blow to KGB operations in Britain, most analysts here doubt that it will do serious damage to British-Soviet relations in the long term. During his visit to Britain last December, Gorbachev impressed many British officials, and Prime Minister Margaret Thatcher said her government "could do business" with the Soviet leader. In the past, the Kremlin usually has allowed major spy scandals to blow over and let relations return to normal after an initial diplomatic outcry.

French President Francois Mitterrand, who ordered the expulsion of 47 Soviet officials in 1983, is now preparing to receive Gorbachev on what will be his first visit to a western country as Kremlin leader. The spying incident is regarded as closed by both the French and the Soviets.

British officials said that Gordievski, 46, whose formal position was political counselor at the Soviet Embassy here, joined the KGB in 1963. For the next 10 years, he worked at KGB headquarters in Moscow, running agents abroad before specializing in Scandinavia, East Germany and Britain.

In a television interview, Danish Justice Minister Erik Ninn-Hansen suggested that Gordievski may have cooperated with western intelligence services since the early 1970s. The minister said that Danish and British security services had been in contact with each other about the Soviet diplomat, whom he described as "an extremely important source of information of significance to our security."

The Foreign Office summoned the Soviet charge d'affaires, Lev Parshin, this morning to notify him of the expulsions.

A British official said that Parshin was informed that the overall ceiling on the number of Soviet officials allowed to work in London would be lowered by 23 following the expulsions. But, in an apparent attempt to reduce the likelihood of Soviet retaliation, the subceiling for Soviet diplomats (as opposed to journalists, businessmen and other ancillary personnel) has been raised slightly to 46.

There are 43 British diplomats accredited in Moscow.

The Soviet Embassy in London issued a statement describing the expulsions as "an unwarranted action of unfriendly character," which "contradicts British statements about their interest in developing relations with the Soviet Union." The Soviet statement said Britain would have to bear responsibility for the consequences of "this provocative action."

Peter Reddaway, a senior lecturer at the London School of Economics who specializes in Soviet affairs, predicted that there would be some kind of "tit-for-tat response" by the Kremlin. "There will be an awful lot of huffing and puffing in the short term and an awful lot of righteous indignation and denials. But once the dust has settled after a few days, I suspect it will be very much business as usual," he said.

British officials said that Gordievski, who has worked in London since 1982, had helped to organize Gorbachev's visit to Britain last year. They said that, as a KGB officer handling sensitive information on a daily basis, he had extensive knowledge of Soviet espionage operations.

Gordievski also will be valuable to western intelligence agencies for the insights he can provide into Soviet thinking and strategy at a time of renewed East-West contacts. He could also presumably identify any Britons working for the KGB.

The officials declined to give precise indications of Gordievski's present whereabouts other than to say that he was still in Britain.

The Soviet diplomats who have been told to leave Britain include three embassy first secretaries -- Yuri Ejov, Vyacheslav Kalitin and Boris Korchagin -- as well as second secretary Anatoly Meretikov and attache Dimitri Vasilev.

Former foreign secretary Lord Home, who ordered the 1971 expulsion of the 105 Soviet officials, said recently that expelling Soviet spies was like dealing with garden pests. "Now and again, you have to use the spray," he said.