President Leonid Brezhnev of the Soviet Union pledged today to keep Soviet troops in Afghanistan "to the end." But his spokesman denied that Moscow wants to occupy that country and added that there are no plans to send in more troops unless outside intervention further intensifies pressure on the Marxist government there.

In rejecting a plea from Prime Minister Indira Gandhi of India for a Soviet troop withdrawal, Brezhnev repeated Moscow's assertion that armed intervention supported by the United States and Pakistan forced the Soviet Union to send the Red Army into Afghanistan to protect its southern border. u

He said the only way to create conditions for the 85,000 Soviet troops to withdraw would be for the neighboring states of Iran and Pakistan to agree to talks with the Afghan government -- a step opposed by those countries as well as the United States on grounds it would legitimize the Moscow-installed government of Babrak Karmal.

The United States and Pakistan have denied instigating what most Western observers believe is a homegrown revolt by Afghans against Soviet intervention. The revolt appears to have intensified into a mass movement since the Soviet invasion last December as a result of the Afghans' traditional hatred of outsiders trying to run them.

As a result, observers here and in the Afghan capital of Kabul believe the Soviets would need five times as many troops to completely pacify the country. Promising not to increase their troop strength, therefore, seems to indicate Moscow is willing to tolerate a continued strong rebel presence in the countryside.

For the second time in two days, meanwhile, the Soviets appeared to be talking over the heads of their Indian hosts and appealing to the incoming Reagan administration in Washington to chart a nonconfrontational course for U.S.-Soviet relations.

This seems to be part of a calculated campaign by Moscow to disparage the Carter administration, especially the President's national security adviser, Zbigniew Brzezinski, for renewing the cold war while suggesting that President-elect Reagan could bring back the era of detente.

The campaign could also set the stage for Moscow to blame the United States if relations between the world's two superpowers fail to improve by saying that it was rebuffed in its efforts to pull the Reagan administration toward a tension-relaxing policy.

The Soviets may have embarked on this campaign here when they found they could not persuade the Indian government to support their military moves in Afghanistan. India still remains, however, one of the few major noncommunist nations not to condemn the Soviet Union for its invasion of Afghanistan, a nonaligned state.

Despite fulsome statements by Gandhi, Brezhnev and their official spokesmen on the enduring nature of Indo-Soviet friendship, slight strains appeared today in the normally smooth relations between Moscow and its faithful friend.

These strains showed up in a joint press briefing during which both sides tried to score points. Brezhnev's spokesman, Leonid Zamyatin, answering a question from a Soviet correspondent, talked only about American naval forces in the Indian Ocean, while Indian spokesman J. N. Dixit broke in to say his country objected to "increased military naval presences from several countries," including the Soviet Union.

According to Dixit, Gandhi told Brezhnev during their two-hour meeting this morning that India opposes "all categories of interference which have affected the sovereignty, progress, prosperity and nonalignment of the people of Afghanistan."

Brezhnev, according to Zamyatin, insisted Soviet troops will have to remain until the United States and Pakistan end what he called their armed intervention in Afghanistan, which he said has become "more intensive." Brezhnev was quoted as telling Gandhi that the Soviet Union "would fullfil to the end its duty of providing assistance to friendly Afghanistan."

In a speech at a midday civic reception for Brezhnev that followed their talks, Gandhi hinted at the differences between the two countries over Afghanistan and indicated the possibility that Brezhnev had tried to pressure her to change India's stance.

She called Indo-Soviet friendship "of equal importance" to both countries and said "neither country has ever sought to impose its perceptions on the other. Yet our agreement on vital issues outweighs divergence."

It was after the joint Indo-Soviet press briefing that Zamyatin selected an American reporter to provide the foil that allowed him to expand at length on the Soviet Union's Afghan position.

"We are not planning to introduce any new troops into Afghanistan if among those who are organizing the intervention, if among those people, reason prevails and they will decide on a course of seeking a political settlement," he began.

In one of several jibes he took at the Carter administration, he added, "I won't mention the states that instigated or organized this intervention, for after all you are going to have a new administration soon."

Then he sent a possible signal to Reagan that Moscow might accept a neutral Afghanistan by laying out the Soviet's strategic needs in the region. n"We are definitely against the appearance on our southern border," he said, "of a state that would be hostile to us, that would endanger our security."