The Soviet Union tonight said it had sent a "limited military contingent" to Afghanistan soley to help repel internal subversion fomented by the United States and China, and denied any role in the Thursday coup that brought a close Moscow ally to power in Kabul.

In an authoritative article in the Communist Party newspaper Pravada, the Soviets asserted they will withdraw their troops "completely" only when the alleged foreign aggression ends. They did not describe the size of the force, which Washington has placed at about 25,000 troops.

The Pravda article, to appear in Monday's editions, was released in full translation by the Tass agency tonight. Portions of it were read on television tonight as well, which emphasizes the importance attached to it by the leadership.

Without naming President Carter directly, Pravda bluntly rejected his warning yesterday that the Soviet intervention in Afghanistan is a "grave threat" to world peace The newspaper declared that "such allegations . . . have nothing to do with reality. But (they) expose the real intentions of certain overseas circles hostile to the struggle for freedom and independence."

Attributed to "Alexei Petrov," a signature used to convey highest Kremlin views, the article sharply attacked the United States, accusing it of plotting with China to subvert Afghanistan as a replacement for having lost Iran after the shah's downfall early this year.

"Cracks appeared in the potorious 'strategic arc' that Americans have been building for decades close to the southern borders of the Soviet Union and in order to mend these cracks, it sought to bring under its influence the Afghans and other countries in the region," the article said.

Kabul has turned "many times to Moscow since the April 1978 pro-Marxist coup in Afghanistan, Pravda claimed. Kabul came "specifically with requests for military aid in response to armed interference by imperialist forces," Petrov asserted. Henewed Soviet attempts to separate the Thursday coup that installed the latest pro-Marxist leader, Babrak Karmal, and Soviet military intervention which began the same day.

"The allegations spread now by imperialist propanganda about 'Afghanistan's occupation by Soviet troops,' about involvement of Soviet military personnel in internal affairs in that country, about 'the U.S.S.R.'s interference internal affairs constituting a threat to international peace' have nothing to do with reality," Pravda declared.

It said the original Kabul engime of Nur Mohammbed Taraki had been overthrown last September by Hafizullah Amin because Amin was a secret western agent intent upon undoning the socialist revolution. Pravda made no mention of the Moslem tribal uprising, calling the insurgents simply "counterrevolutionaries."

Amin in turn was toppled because of a popular revolt that installed Babrak, Pravda said, offering no explanation about how Babrak arrived in Kabul together with other former members of the original Taraki government who had been purged some months ago and reportedly gone undergrown in Eastern Europe.

Petrov said Moscow responded to a new "insistent request that the Soviet Union should give immediate aid and support in the struggle against external aggression." He based the intervention on the Dec. 3, 1978, Kabul-Moscow friendship treaty, and on Article 51 of the U.N. charter "that envisions the inalienable right of states to collective and individual self-defense to rebuff aggression and restore peace."

The tough Pravda account sketched a lurid picture of American, Chinese and Egyptian secret agents organizing guerrilla strikes from refugee camps in Pakistan. There are an estimated 350,000 refugees there, many of them sympathetic to the Moslem insurgency that has cut deeper and deeper into the narrow base of the Kabul communists.

Pravda sought to reassure Iran and Pakistan, which have sharply denounced the intervention.

"Soviet assistance to and support of Afghanistan is not directed against any of its neighbor countries that also are our neighbors," it declared. "The U.S.S.R. is interested in maintaining normal friendly relations with them, the relations based on the principles of equality, mutual respect and noninterference in internal affairs."

The Soviets said that the Moslem tribesmen opposed to the Kabul government "were receiving unlimited backing from the imperialist circles of the United States, the Peking leaders and governments of some other countries that were lavishly supplying the counterrvolutionary gangs with weapons, equipment and money."

Pravda alleged a connection between the bloody uprising in the regional Afghani city of Herat earlier this year in which dozens of Russian advisers are thought to have been killed, and a State Department visit by "one of the ring lieaders" of the rural insurrection.