The movement of nonaligned nations tonight overrode the strong objection of members friendly to the Soviet Union and called for the withdrawal of "foreign troops" from Afghanistan and "foreign forces" from Cambodia.

The decision by the 92 members of the world's largest and most diverse bloc marked a sharp shift from the 1979 Havana summit when it appeared that the nonaligned movement was tilting toward the Soviet Union.

In a separate move on an issue with overtones other than the East-West equation, the nonaligned nations followed the lead of the recent meeting of the Islamic conference and urged member states to vote against accepting the credentials of the Israeli delegation at the next meetings of the United Nations or its specialized bodies. Since the nonaligned nations form a majority in the United Nations, Israel could be deprived of its U.N. vote if the member states follow through on the communique agreed upon here today.

The nonaligned states said they took this stance because of what was described as Israel's violation of international law and its annexation of Jerusalem. The first opportunity for the nonaligned states to act under the new policy will come in June when the International Labor Organization, a U.N. body, meets in Geneva.

In its overall tenor, this meeting of foreign ministers appeared to signal the movement's rejection of the argument by the Cuban representative, the current nonaligned chairman, that the Soviet Union was the real ally of nonaligned nations.

Instead, the members tried to exhibit evenhandedness in their references to the United States and the Soviet Union. For example, the ministers deleted a specific reference to the U.S. naval base on the Indian Ocean island of Diego Garcia because there was no corresponding mention of Soviet military facilities in the region.

The resolution as passed opposed "military presences of all the great powers" in the Indian Ocean, where both the Soviets and Americans have large fleets.

Nor was the Soviet Union directly named in the resolution on Afghanistan despite the presence of 85,000 troops who invaded that avowedly nonaligned nation in December 1979 and installed the government of Babrak Karmal.

The resolution "urgently calls for a political settlement on the basis of the withdrawal of foreign troops" and observance of the norms of noninterference and nonintervention.

Thus the nonaligned movement backed Pakistan, which has demanded the withdrawal of the Soviet troops from its border, and yet gave credence to the view of India and some other countries that the Soviet invasion was caused by foreign backing of Afghan rebel bands.

Afghanistan and Vietnam both called the resolution "absolutely unwarranted" and said it was interference in the internal affairs of Afghanistan, which had invited the Soviets in to protect its government from foreign aggressors.

Although they did not name the aggressor, in the past Afghanistan has accused Pakistan, the United States and China of supplying and training the Afghan rebels, some of whom are based in Pakistan.

The objections by the two member states broke the code of censensus that the nonaligned movement generally observes to form its positions. In this case as well as in regard to Cambodia, a number of members blamed a minority for using the consensus rule to try to thwart the will of the majority of the nonaligned states.

Cambodia, a nonaligned state not seated at this meeting, posed an equally thorny problem for the movement.

The Asian nations of Singapore, Malaysia and Indonesia insisted that the movement call for the withdrawal of Vietnamese troops from Cambodia. The Vietnamese, who are backed by the Soviet Union, invaded Cambodia in 1979, overthrew the communist regime of Pol Pot and installed another under Heng Samrin.

In its resolution, the nonaligned world did not name Vietnam, also a member nation, but called for withdrawal of "foreign forces." Conference sources said the three Asian nations formed an informal alliance with Pakistan on both the Cambodian and Afghan issues to force changes in the draft presented by India, which had not called for troop withdrawals.

There were fears as this meeting started that the nonaligned movement, which on Wednesday celebrated its 20th anniversary, would lose credibility if it failed to take stances on the invasions of Afghanistan and Cambodia and the five-month-old Persian Gulf war between members Iran and Iraq.

It moved today to seek a settlement of that way by offering a set of principles both sides might accept and by naming a committee of foreign ministers to end the fighting.

The Westward tack of the nonaligned movement was spurred by the Soviet invasion of Afghanistan, according to Indian observers. Kuldip Nayar, a columnist for the Indian Express newspaper, said stock phrases were closely checked to make sure they did not signify a pro-Soviet bias.

Despite fears among some members that the movement might swing so far to the West that it would develop a pro-U.S. stance, the United States came in for criticism.

One resolution called for self-determination and independence in Puerto Rico, even though the island has consistently voted to remain part of the United States. A Puerto Rican independence group has observer status in the nonaligned movement.

Another resolution called for the return of the U.S. naval base at Guantanamo to Cuba.