Roy Medvedev, the Soviet historian known in the West for his study of Stalinism, has been formally warned that he must cease his "anti-Soviet activities" or face criminal charges for damaging "the interests of the Soviet state."

The move against Medvedev, who with the exception of physicist Andrei Sakharov is the most respected independent intellectual voice in the country, has come during what seems to be a general crackdown against dissent by the new Soviet leadership.

Medvedev was summoned yesterday to the office of the Soviet procurator general, the nation's top law enforcement officer, to be served with a written statement in which his books and articles were described as "pamphlets" that "slandered the Soviet social and political system."

The 56-year-old Marxist historian, whose independent views and activities have made him a political anomaly here, said today he had categorically rejected the charge. In a written statement to the procurator general, Medvedev accused the investigator's office of "crudely violating" the Soviet constitution.

While Sakharov had become a political dissident and was sent into internal exile more than two years ago, Medvedev is a Marxist who advocates democracy and a supporter of human rights who preaches caution and gradualism.

The sudden warning to Medvedev followed a move against a prominent writer, Georgy Vladimov, 52, who was threatened with criminal charges for alleged anti-Soviet activities if he fails to submit by Thursday a letter renouncing such actions and pledging not to publish his works abroad.

Several lesser known dissidents have been arrested or interrogated recently in what seems to be a general crackdown by the new Soviet leadership formed when president Leonid Brezhnev died in November.

The crackdown can be placed in the context of a nationwide drive for stricter social and economic discipline.

In an interview today, Medvedev said Deputy Procurator General Oleg Sorok had told him that "either you cease writing such articles and books or we shall put you in jail." Medvedev also quoted Sorok as saying that this was a message from "the leadership" which was urging the historian to "engage in socially useful activities."

No specific complaints about his writings were mentioned, Medvedev said. His best known work, "Let History Judge," was one of the earliest and most detailed accountings of Stalin's crimes. It appeared in 1971, two years before the publication of Alexander Solzhenitsyn's "Gulag Archipelago." His latest work is a biography of the late party leader Nikita Khrushchev, published last year.

Defending his position, Medvedev said in his statement that his only aim was to see his country living in peace and flourishing in socialism and democracy. But, he said, corruption and misuse of power in "our recent past" had infiltrated the Kremlin leadership including the legal system, the procurator's office and the KGB secret police."

"In a country such as the Soviet Union," he said, "any honorable historian" must pursue his work irrespective of whether it is pleasing to those in power. "Therefore I am but little concerned what assessment of my work is made by the procurator's office or the KGB," he said.

"Any honest and independent historian must be concerned only by one thing--the search for truth. I am not afraid of any potential punishment and therefore it does not make much sense to make any warnings on this account or to resort to undignified threats."

He concluded: "I consider that the interference of your deputy in my work is unjust and illegal, and I ask that in the future I be protected from such actions, which are undertaken not for the first time."

Medvedev told journalists that Sorok was polite during their conversation although he flatly refused to point out what were the offending passages or assessments in Medvedev's 19 books published outside the Soviet Union since 1971. Nothing except his pedagogical writings has been published here.

Sorok did not specify possible charges, but Articles 70 and 190 of the criminal code cover offenses dealing with anti-Soviet activities.

"The fact that for 20 years we did not call you in," Medvedev quoted Sorok as saying, "is a reflection of our great patience. But this patience is coming to an end. We have very little patience left, and it may run out in the course of this year."

The law and order campaign has touched virtually all phases of Soviet life and includes police raids on shops, public baths, restaurants and even trolley buses. The aim of these massive raids is to identify vagrants and absentee workers.

A new government order called for internment of "social parasites" such as drug addicts and alcoholics in new treatment centers, subject to corrective labor coupled with "social reeducation." Another move announced today threatened factory and farm managers with punishments if they fail to purge alcoholics from their work force.

Medvedev disclosed today that he had been warned twice before by regional officials of the procurator's office against continuing "anti-Soviet activities." He said he had rejected those warnings as well. He also said that the KGB had attempted last year to search his apartment but that he had told them they could do so only if they arrested him.

A compromise was reached under which the agents catalogued all the books in his library without actually carrying out a search of the premises.

He said KGB agents also called on him on Nov. 13, shortly after Yuri Andropov succeeded Leonid Brezhnev as Communist Party leader, to warn him against criticizing the new leadership. The call presumably was made because of Medvedev's contacts with western correspondents in Moscow.

While he has been available to journalists for discussions of various aspects of Soviet life, Medvedev's public statements were confined to well documented and reasoned books and articles. He always calibrated his activities to the mood of the moment. His caution and Marxist outlook allowed him to carve out a place for himself with the freedom to write.

Expelled from the Communist Party in 1968, Medvedev has been living quietly in a small apartment at the northern edge of Moscow.

Medvedev's twin brother, Zhores, a geneticist, was an active member of the dissident movement from the late 1960s until his ouster from the Soviet Union in 1973. Stripped of his Soviet citizenship, Zhores Medvedev now lives in Britain.