The Indian and Pakistani foreign ministers ended two days of talks here today with wide differences remaining over how to get Soviet troops out of Afghanistan and about an arms race in the region.

In their main areas of agreement both nations said they favor the withdrawal of Soviet troops from Afghanistan and oppose making the region a cockpit of U.S.-Soviet rivalry. But they came up with no way to achieve their aims.

"We are not embarking on a common strategy," said Pakistani Foreign Minister Agha Shahi.

Emphasizing the differences, Indian Prime Minister Indira Gandhi told Shahi that the Soviet invasion must be seen as part of the increasing American military presence in the Indian Ocean and Persian Gulf. Moreover, sources close to the talks between Shahi and Indian Foreign Minister P. V. Narasimha Rao reported that Pakistan was told it must talk directly to the Soviet-installed Babrak Karmal government in Kabul if it wants a Soviet troop pullout.

Shahi emphasized Pakistan's willingness as a member of the three-nation Islamic Conference committee to talk to Babrak, but only as a leader of the ruling People's Democratic Party of Afghanistan since the Islamic foreign ministers agreed not to recognize the Afghan government.

The differences over Afghanistan were expected. But the effect of India's $1.6 billion arms purchase from the Soviet Union, announced last month, emerged as a new divisive issue between the two neighboring nations -- which have fought three wars in the nearly 33 years since they were carved from British India and given their independence.

While both countries agreed to postpone discussions of a possible arms race until a later time, the subject kept cropping up in briefings, formal speeches and parliamentary questions.

In his speech last night, Shahi said India's purchase of "larger quantities of sophisticated weapons" causes apprehension. He proposed "as a confidence-building measure" that the two nations open arms reduction talks.

India rejected the proposal, and at a private briefing for Indian journalists, Rao was reported to have rebuked Shahi for bringing up the question. Earlier India's official spokesman said Gandhi had complained to Shahi over "adverse publicity about India and its defense policies which have appeared in newspapers ahead and in some Pakistani papers."

Meanwhile, Gandhi told a parliamentary questioner who asked about "Pakistan arming itself to the teeth" that she made it clear to Shahi that his nation's arms purchases do not help keep the peace in the region.

Shahi denied that Pakistan has received any new arms during the past three years. He said Pakistan "certainly is not arming itself to the teeth. There is the wrong impression in India."

Indian news articles and editorials continually refer to large purchases of arms by Pakistan since the Soviet invasion of Afghanistan, although Western diplomats here back up Shahi's denial. The Pakistanis last February rejected as "peanuts" a U.S. offer of a $200 million loan at 11 percent interest to buy arms.

While there is no secret that Pakistan is seeking funds from other sources, especially some of the oil-rich Islamic nations such as Saudi Arabia, it has had no success as yet in finding a backer for arms purchases.

The Pakistanis have charged, moreover, that India's arms purchase from the Soviets is actually worth $9 billion -- not the $1.6 billion announced -- because of the unusually favorable terms of the loan (2.5 percent interest for 19 years) and the low price of the weapons (estimated at about one-third the going price for comparable equipment).

Shahi tried to reassure India that there was no reason for the two countries to arm against each other.

"India is a very large and powerful country," he said, "and has no reason to feel threatened by any of its neighbors. . . . Pakistan is a much smaller country which has neither the intention nor can ever acquire the capability of posing problems for India. In fact, a strong Pakistan capable of defending its frontiers would strengthen India's own security."

At a press conference today, Shahi also said Pakistan wants broad international participation in any Afghan withdrawal plan to make sure the United States and Soviet Union do not reach a private agreement that would carve up the region into separate spheres of influence.

He repeated Pakistan's denial that it has embarked on a nuclear weapons program or is arming and training Afghan rebels.