British Prime Minister Margaret Thatcher tossed a direct challenge to Indian policy here today by insisting that Pakistan needs arms to defend itself against Soviet troops across its borders in Afghanistan.

It was some of the firmest and bluntest language the Indian press and government officials have heard on Pakistan's need for arms. It came in the third day of the prime minister's five-day state visit here.

At a news conference, Thatcher also challenged other cornerstones of Indian foreign policy when she justified the presence of Western naval ships and bases in the Indian Ocean-Persian Gulf region as necessary to protect vital sea lanes and to counter the Soviet force in the area, blamed the Soviet occupation of Afghanistan for tensions in the region, and defended Washington's plans for a military Rapid Deployment Force to which, she added, Britain would send a small contingent.

She stood firmly behind a proposed British nationalities law, a measure that one Indian correspondent referred to as "paper genocide" in the midst of a question. He was reflecting the widely held view here that the measure is aimed at stripping dark-skinned residents of former British colonies of their rights to full British citizenship. She said Indian fears were based on misinformation.

But it was in her comments on international issues that Thatcher most opposed the views of the government of Prime Minister Indira Gandhi, which blames the West for increasing tensions in the region and fears that new arms to Pakistan will be turned against India.

Thatcher's challenge came in the midst of an Indian diplomatic offensive to counter American efforts to conclude a new security relationship with Pakistan, with which India has clashed several times, and to increase the Western naval presence in the Indian Ocean.

A top Indian diplomat, Eric Gonsalves, is in Washington this week trying to persuade the Reagan administration to shift its policies.

Thatcher stressed the right of any country to acquire arms to defend itself and said Pakistan's needs have increased since the Soviet invasion of Afghanistan in December 1979.

"I would be concerned if I had Soviet troops near my frontier that had recently occupied the country just beyond that frontier. I would wish to have the means to defend myself and my people," the British leader said.

She said that India, which recently concluded a $1.6 billion arms deal with the Soviet Union and has also contracted to buy jet fighters from Britain, "has increased her equipment and arms enormously, more so than some other countries because she does in fact give priority to being able to defend herself."

"One cannot ask for a right to defend onself," Thatcher added, "and deny that right to other sovereign nations."

While Thatcher said she opposes military intervention in Afghanistan to dislodge the 85,000 Soviet troops there, the British prime minister added, "We shall never accept the Soviet occupation of Afghanistan as normal and we shall look at every activity of the Soviet Union accordingly.

"Once you accept that the Soviets can march in an occupy an independent country, no independent nation will be safe."

She said Britain is trying to put pressure on the Soviets to withdraw through the United Nations, the nonaligned movement, the countries of the Commonwealth and other diplomatic channels.

Thatcher defended the U.S. naval presence on the British island of Diego Garcia. In reply to a question asking if Soviet withdrawal from Afghanistan should be accompanied by a similar U.S. withdrawal from Diego Garcia and from El Salvador, Thatcher said, "I am not aware of any foreign troops in El Salvador."

She laid the increasing Western naval presence in the Indian Ocean-Persian Gulf on the Soviets, who she said "have a large number of ships" in the region.

She said the British, French and American ships there are needed to make sure the vital sea lanes are kept open.

"It would be very nice," she said, "if you could maintain freedom of navigation without any naval ships of any nations there at all. But I am afraid that is not what the world is like. It is a very, very sensitive area . . . . I do not see any changes at the moment."

Thatcher tempered her hard words on Indian foreign policy with soft tones and a ready smile as she appeared to lecture the Indians.

Despite the obvious and sharp differences, the two leaders appeared to hit it off well during their three days of talks.

There was, in fact, little effort made to paper over the differences between them. Asked today what the areas of agreement were between her and Gandhi, Thatcher spoke only in the broadest generalities.

"We all want peace. We all want stability. We all want a level of armaments a good deal less than we have now. We are all going to a conference on the Third World in Mexico," Thatcher said.

But the two prime ministers signed a memorandum yesterday calling for more commercial and trading relations between Britain and India. When Thatcher took off this afternoon for a two-day visit to Bombay, Gandhi stood in the hot sun at the airport to wave goodbye -- a sign that, despite policy differences, they retain high personal regard for each other.