MOSCOW, SEPT. 3 -- Oleg Kalugin, a former KGB major general who was stripped of his military rank after criticizing the Soviet security agency, has been elected to the legislature of the Russian republic despite strong opposition from President Mikhail Gorbachev and KGB officials, according to runoff results made public today.

Kalugin, 55, who worked for the KGB for 32 years in Moscow, Leningrad and at the Soviet Embassy in Washington, among other assignments, had campaigned against what he called the security agency's "secret world."

Kalugin, the highest-ranking KGB officer ever to openly criticize the agency, was stripped of his rank and decorations by Gorbachev in June after he denounced the KGB as a "tool of the Communist Party" and accused it of spying on political activists. He had been forced to retire from the KGB earlier this year after publishing an article calling for reform of the agency.

The KGB has said it will press criminal charges against Kalugin, but as a member of the Russian legislature, he will have legal immunity.

Kalugin's victory in Sunday's vote in the south Russian region of Krasnodar marked a humiliating defeat for the KGB and the party, which went to great lengths to derail his campaign. At one of Kalugin's political rallies last month, two planes buzzed overhead and dumped thousands of leaflets on the crowd promoting one of his opponents, an army general.

Kalugin said his victory showed that even in a traditionally conservative region of the country dominated by the Communist Party organization, "the forces of radical democratic change have the greatest public support."

The former KGB officer said he would seek membership on the legislature's committee on defense and state security. Russian leader Boris Yeltsin also has called for "fundamental reform" of the KGB, saying it should "protect the individual, not haunt him."

Kalugin has filed suit against Gorbachev, KGB chief Vladimir Kryuchkov and Prime Minister Nikolai Ryzhkov for stripping him of his honors and rank. In the past two years, Kryuchkov has carried out a public-relations campaign citing reforms in the KGB, but Kalugin has called the campaign a "fraud."

Although Yeltsin never campaigned for Kalugin, the former KGB officer received help from some of Yeltsin's supporters in the legislature, and he borrowed heavily from Yeltsin's anti-establishment style.

For more than two months, Kalugin has put forth his message on television and in newspaper interviews, criticizing the "ubiquity" of the KGB in everyday life and contending that it continues to monitor political activists and plant informers in schools, workplaces and military units.

Vladimir Friedland, an aide to Kalugin, charged that the Communist Party, which controls the main newspapers in the Krasnodar region, refused to allow Kalugin to advertise the times and places of his rallies.

Kalugin, who had placed first in recent general elections, drew 58 percent of the vote in Sunday's runoff balloting against a Communist Party official, today's results showed. He won a seat left vacant when the region's conservative party leader, Ivan Polozkov, became head of the Russian republic's party organization.