YAROSLAVL, U.S.S.R. -- They did not know it at the time, but the small band of demonstrators who protested against Yaroslavl's longtime Communist Party boss had an influential ally: the head of the local KGB security police.

Angered by the selection of the former Yaroslavl party chief, Fyodor Loschenkov, to be a delegate to the extraordinary Communist Party conference in July 1988, reform-minded Communists staged a demonstration at a park in this provincial city on the Volga River. The police did not intervene.

The protests against Loschenkov, popularly known as "Czar Fyodor" because of his autocratic ways, provided the springboard for the formation of the Yaroslavl Popular Front, one of the first grass-roots opposition groups in the country. They also encouraged Maj. Gen. Alexander Razhivin, the local KGB chief, to criticize Loschenkov, during a closed party meeting, for economic mismanagement.

"Our agents observed the demonstration. Nobody shouted, 'Down with Soviet power.' They just said that Loschenkov was someone they could not trust. We decided that there was no work for the KGB {there} and we were proved right," said Razhivin, in a rare interview with a local KGB chief by a Western journalist.

Just a few years before, any attempt to stage a political demonstration in a Yaroslavl park would undoubtedly have been broken up by KGB agents. The decision to allow the protest to proceed and Razhivin's own subsequent criticism of Loschenkov illustrate the significant role played by the KGB in shepherding Mikhail Gorbachev's perestroika reform program.

As head of the KGB in Yaroslavl for the past decade, Razhivin has been a key backstage player in the political revolution that has taken place in the town. Popular Front activists refer to him sarcastically as "our democrat" because of his tacit support for their organization in its early stages. More recently, he has taken a tougher line in criticizing attempts to cut back the security services and called for vigilance against foreign agents.

In the two-hour interview, the 60-year-old KGB chief presented himself as a committed supporter of Gorbachev and the process of democratization in the Soviet Union. He also brushed aside suggestions by Oleg Kalugin, a former associate in the agency's counterintelligence wing, that the KGB has not changed significantly under Gorbachev, despite a public relations campaign designed to improve its gruesome image.

"Of course there have been changes in the KGB. Our organs reflect the changes that have been taking place in society," the general said. "If you had come here in 1985 and asked to see me, I would have said that either you are mad or I am mad. Is not this perestroika, the fact that you can meet with me? I think we will soon be able to say that we are a law-governed state. Russia has gone through many cataclysms, but this day is coming soon."

Just what the KGB does these days in a city like Yaroslavl is still somewhat mysterious. Razhivin said the agency is now being used to fight organized crime, but he acknowledged that its primary task is "counterintelligence." He refused to say how many agents work under him, but did reveal that the number has neither decreased nor increased in the five years of perestroika. The KGB is building itself a modern headquarters in the center of the city, capable of housing several hundred officials.

The Yaroslavl KGB has cooperated with local political activists to rehabilitate Stalinist victims. Of the 18,000 people sentenced to prison or firing squad in the Yaroslavl region in 1938 and 1939 -- the worst years of Joseph Stalin's purges -- 10,000 have already been officially exonerated. This week, KGB officials plan to help excavate an unmarked burial ground about 15 miles out of town where the bodies of people executed by firing squads during the purges were dumped.

"Razhivin's a good lad," said Yuri Markovin, head of the local branch of Memorial, a group that is campaigning for the full rehabilitation of all Stalin's victims. "At first the KGB was cold toward us, but now they are satisfying most of our requests."

When Razhivin entered the secret police in 1952 as an idealistic young Communist, Stalin was still alive. The agency was headed by Lavrentin Beria, now widely denounced as a mass murderer. But Razhivin, who is due to retire next year, insists that he has no reason to feel ashamed of his chosen career.

"There is no need for us to repent. I refuse to answer for Beria's crimes. Now there is a new generation in the KGB. These are completely new people. Why should they be responsible for the actions of their predecessors?" he said.

Asked what the future holds for Yaroslavl, Razhivin described the creation of a multi-party system as an "irreversible" process. He said that Gorbachev has made political "mistakes," including the decision to form a giant agricultural ministry known as Agroprom and the bungled anti-alcohol campaign that cost the state billions of rubles.

"There will be more mistakes in the future," predicted Razhivin. "But Gorbachev's great service is democracy and glasnost {openness}. He does not hide what we have achieved and what did not work out. . . . Whoever takes control of the state in the future will have to consider these accomplishments."