Mozambique tonight signed a treaty of friendship and cooperation with the Soviet Union, making it only the third black Africa nation to establish such close formal ties with Mosocw.

The terms of the treaty were not immediately made known but they were presumed to be similar to those contained in the one signed last year between Angola and the Soviet Union. The only other black Africa country to have concluded such an accord with Moscow is Somalia, where the Soviets have made their largest military and economic investment in Africa.

The treaty marks in a dramatic manner the consolidation of Soviet influence in southern Africa, particularly since it has been signed with a country that borders directly on white-ruled South Africa.

At the singning ceremony at the presidential palace, Mozambican President Somora Machel said, "Today we are mixing the blood of the Soviet people with that of the Mozambican people.

"The signing of this document not only satifies the desire of our two peoples but it will also be a contribution to humanity and above all to the socialist world," he added.

Visiting President Nikolai Podgorny, who signed for the Soviet Union, replied that relations between the two countries had now reached "a verh high level. If the texts of this agreement is completely carried out we can say that the friendship between our two peoples, parties and governments will be one of steel."

The signing of the treaty is bound to shake Mozambique's relations both with South Africa and China. South African leaders have been looking with increasing apprehension at the development of Marxist-Leninist governments with close ties to the Soviet Union in southern Africa even while continuing to provide massive indirect aid to the one here in Mozambique.

China, which was regarded as the most favored Communist nation here immediately after Mozambique's independence in June 1975, now appears to have lost out heavily to the Soviet Union.

Whether the treaty will result in any policy changes toward Mozambique in Pretoria and Peking remains to be seen.

Even before it was disclosed that the two countries intended to sign the treaty, Mozambican officials were cautioning Western journalists against interpreting that Mozambique was becoming a Soviet "satellite."

President Machel had earlier spoken of his desire to establish an "examplary relationship" with the Soviet Union, which he termed a "natural ally" of his Marxist government."

Still, the decision by Machel to identify Mozambique to closely with the Soviet Union is certain to come as a surprise to many Western and nonaligned diplomats.

The prevailing view in Western deplomatic circles has been that Mozambique is intensely nationalistic, determined to maintain its independence and unlikely to provide naval bases or other facilities to any of the major powers. Whether this view will hold after the signing of the friendship treaty with Moscow is another question.

The announcement that the two governments were planning to sign a friendship treaty came only a few hours before at a public rally here in honor of Podgorny.

Speaking from the balcony of city hall where Portuguese colonial leaders once made speeches, Podgorny declared his country's solidarity with the African struggle for the "definitive liquidation" of the white recist regimes of southern Africa and said it would oppose any attempt to maintain the present white governments.

"Let nobody be under the illusion that there can ever be conciliation with racists," he said. "Brother of mine," he said to Machel, "you will not be alone in the struggle."

Podgorny also hailed Mozambique's decision in February to establish a Marxist-Leninist party as a "historic event."

Machel praised the Soviet Union for its support to the Front for the Liberation of Mozambique during its 12-year struggle against Portugal and hailed the developing relationship between his country and Moscow.

The public rally, the only one held for Podgorny on his two-week tour of southern Africa, was attended by about 10,000 people, who took the lead from Machel in repeatedly cheering the Soviet leader.

Across the false Greek facade of the city hall building was strung a huge red banner with the words, "workers of the World Unite," and two big portraits of Machel and Podgorny.

Friday, Podgorny leaves for northern Tanzania where he will tour game parks for a day before departing Sunday for Moscow.