The Soviet Union strengthened its influence on the struggling new Marxist leadership of Afghanistan today, signing a friendship and cooperation treaty with the Kabul government that seems sure to further alarm Western powers already worried about turmoil in adjacent Iran.

It is the third such friendship treaty signed this fall between the Kremlin and Third World countries to buttress the Soviet position there against Western influence on the one hand and against the recent diplomatic moves of Moscow's hated rival, China, on the other. The other treaties were signed with Vietnam and Ethiopia.

The 20-year "treaty of friendship, good neighborliness and cooperation," was signed by Soviet President Leonid Brezhnev and Afghan Prime Minister Noor Mohammed Taraki in a Kremlin ceremony. It pledges the countries to mutual economic, military and technical aid.

The defense clause calls on the Soviets and Afgans to "continue to develop cooperation in the military field on the basis of appropriate agreements between them."

The treaty in effect confirms Moscow's dominance of the Taraki government. His predecessor, the feudal pro-Western Afghan strongman Mohammed Daoud, was deposed and killed in a quick April coup engineered by Marxist sympathizers in the Soviettrained and equipped Afghan army.

The Taraki government and its Khalq (People's) Party have since proclaimed a socialist revolution and announced ambitious plans for land reform and farm collectivization as well as a five-year economic development plan aimed at pulling the backward country toward industrialization. Western sources report that thousands of Soviet advisers are in Afghanistan to help direct this effort, as well as solidify control of the Kalq, a party with little popular base.

The strong Moscow influence has upset Western strategists, worried about the impact on troubled Iran to the west, as well as on the other Persian Gulf states whose oil is vital to the West. The Afghan developments also are seen as a threat to Pakistan to the east, which itself is plagued by a protracted government crisis. The Afghans and Pakistanis have long contended over Baluchistan in southern Pakistan.

The Taraki government could give covert aid to a leftist separatist Baluchi movement, which could in turn contribute to destabilization of the power balance in the Arabian Sea area. The Russians since czarist times have eyed the area for a possible warm water port. East-West maneuvering and influence in the remote, landlocked country of hill tribesmen and nomadic shepherds dates to the last century, when Britain sought to blunt those expansionist Russian aims.

The Soviets have angrily insisted they had nothing to do with the April coup, but they have clearly been the beneficiaries at Western expense and are moving swiftly to capitalize on it. When Taraki led a delegation here for talks, some Western analysts were speculating that the Kremlin would not sign a friendship treaty with so new and shaky a government.

But the fact of the quick signing can be interpreted as a sign of the dependence of the new Kabul leaders on the Soviets for ideological, economic and military support, and of Kremlin eagerness to exploit the opportunity in a country with borders that front directly on nations in the Western camp.

The Soviets have treated Taraki with the pomp due a head of state and the state-controlled media have reported in detail on these matters.

The friendship treaty specifically declares that the Soviet Union "respects the policy of nonalignment" of the Taraki government. Taraki repeatedly has stressed that he is pursuing a policy of neutrality.

The Soviets have tradionally sought friendship treaties with their immediate neighbors to create a special relationship. They also have used them to project Soviet influence into other continents, as with the friendship treaties of the past five weeks with Vietnam and Ethiopia.