President Leonid Brezhnev of the Soviet Union arrives here Monday to try to repair damage that has developed in Moscow's carefully cultivated close relations with India over the Soviet invasion of Afghanistan.

Never before in the quarter-century history of increasingly close economic and political ties between New Delhi and Moscow has the visit here of a major Soviet leader generated so much public hostility.

Brezhnev, for example, was depicted in a front-page cartoon in the respected Times of India on Friday riding on a tank. Opposition politicians have joined with Afghan refugees here to stage an anti-Soviet demonstration Monday over the invasion of Afghanistan. Six opposition members of Parliament delivered a petition to the Soviet Embassy here Saturday calling on Brezhnev to withdraw troops from Afghanistan and keep out of Poland.

As a result of the public controversy, Prime Minister Indira Gandhi warned opposition politicians yesterday against participating in anti-soviet demonstrations, "which will only sully India's name."

In a precautionary move, Afghan refugees in New Delhi were ordered, under threat of deportation, to remain in their homes during the four-day Brezhnev visit. It was unclear today how many of the estimated 20,000 Afghan refugees here are affected by the order, but an Indian official said most are students "capable of mischief."

Even former prime minister Morarji Desai added his voice to the anti-Soviet comments that have appeared in the public press in an unprecedented manner in the week before the Brezhnev visit. Desai said during his term of office that the Soviets kept egging him on to take a harder stance against Pakistan.

Desai's remarks drew strong condemnation from the Gandhi government, with Foreign Minister P. V. Narasimha Rao calling them "unfounded and irresponsible." Government sources said they were especially embarrassing now, just before Brezhnev's visit.

While this hostility is evident, there is no question of India's turning against the Soviet Union, which is New Delhi's largest if not exclusive arms supplier. By all indications, attempts will be made to gloss over the differences while emphasizing the wide areas of agreement.

In a gesture of respect tendered Brezhnev by the Indians, his schedule is very light with long periods of rest. Gandhi and other Indian officials will call on him in his quarters in Rashtrapati Bhawan, the Indian president's mansion, instead of making him go outside.

Yet the public controversy surrounding his visit spoils the warm glow that the Gandhi government and the Soviets are trying to put on Brezhnev's trip to India -- one of Moscow's closest noncommunist friends.

"Afghanistan," said a diplomat here, "is the first thing the Soviets have done that thoughtful Indians find threatening to their country."

The visit of the ailing, 73-old Soviet leader is seen here as an effort by Moscow, rolling out its most powerful diplomatic weapon, to make sure the Afghan invasion does not completely wreck 25 years of otherwise warm relations.

"The Soviets must feel a certain amount of isolation. They are carrying a weak hand," said a high Indian official privy to details of his government's preperation for the Brezhnev talks.

"I am sure," he continued, "that some Soviets will try to get India to give the Afghan venture greater support. But that difference of opinion should not affect greatly our good relations."

India has told Moscow privately that it wants Soviet Troops withdrawn from Afghanistan as soon as possible, but its public statements have been more muted, excusing the intervention as a reaction to the buildup of U.S. forces in the region and a feeling in the Soviet Union that it was being encircled by its enemies.

It is unlikely that either side will change its stance, and most likely the final communique -- already drafted in close to final form -- will stress the areas of economic cooperation where there are no strains and give Afghanistan little if any mention.