Britain announced today that it has expelled the Soviet Union's naval attache in London, accusing him of attempting to set up a spy network in the country -- an effort, officials said, that was uncovered before it did any damage.

The officer, Capt. Anatoli Zotov, was apparently the highest ranking Soviet to be ordered out of Britain since 1971 when more than 100 Soviet personnel were ordered to leave for spying. Zotov, the British said, was a senior officer of the GRU, the Soviet Union's military intelligence agency. His activities, they said, had been monitored by a covert surveillance unit of Britain's own intelligence agency, MI5.

The expulsion of Zotov is the latest turn in what has been a long autumn of espionage excitement in Britain. As announcement of the ouster was being made, the spy trial of an Anglo-Canadian economics professor continued with insistent assertions by the defense that British intelligence had missed the fact that the man, Hugh Hambleton, was actually a Canadian double agent, working against the Soviets rather than with them.

British officials maintained today that none of the recent spate of espionage cases is related. They said, in particular, that Zotov had not been identified by a recent KGB defector to Britain, Vladimir Kuzichkin, or by Geoffrey Arthur Prime, the recently convicted Soviet spy who has promised to tell authorities all he knows.

One bizarre aspect of the Zotov story is that it apparently was leaked to Britain's domestic news agency, the Press Association, last night by the Soviets, who suggested the British were trying to divert attention from their own celebrated intelligence failures.

Not until this morning was the expulsion confirmed by the Foreign Office. Official sources said that the Soviet, who ranked second in the embassy's military unit, arrived in Britain in January. They said his task evidently was to set up an agent network to learn British military secrets. Citing "clear evidence" of his intentions, the sources implied that Zotov had been caught trying to recruit agents. Authorities gave him eight days to leave the country.

In the past 18 months, two other Soviet diplomats, a trade official and a second secretary, have been ordered to leave Britain. The new strength of the Soviet diplomatic staff will be 45.

Officials said they anticipated that a British diplomat in Moscow would be expelled in retaliation for Zotov.

If the activity on the spy front is all coincidental, British satisfaction over breaking an attempted espionage ring is not. The Prime case and other recent examples of lax security have made Prime Minister Margaret Thatcher's government notably defensive about such matters, even though it is not directly responsible for many of them.

One report said that Thatcher intended to announce the ouster of Zotov in Parliament as evidence of good British intelligence work but was preempted by the Soviets.

The Hambleton trial has been underway all week with the defense countering prosecution claims that the professor was an agent for the Soviet secret police, the KGB, for 30 years by contending that he was engaged in counterespionage. Hambleton was ordered in court today to write down the name of his Canadian intelligence contact, presumably so British officials can determine his relationship with Canada.

Hambleton was arrested by the Canadians in 1979 and a substantial amount of espionage apparatus was found in his home, but he was never tried. He was arrested here when he came for a visit last summer.