The Soviet leadership said goodbye to Vietnamese leaders yesterday after a nine-day visit that has left the Kremlin savoring its 25-year friendship and cooperation treaty with Hanoi as a major new weapon in blunting the worldwide diplomatic offensive of its arch-enemy China.

The treaty, signed last Friday and coming on the heels of China's diplamatic successes in Japan, Romania and Yugoslavia, is seen here as advancing these important Soviet goals:

Binding one of Asia's most powerful military machines with the world's second largest conventional arms exporter at a time when China-Vietnam border clashes have escalated and Hanoi allegedly is preparing an attack on neighboring, pro-Peking, Cambodia.

Asserting Soviet interest in Asia after China and Japan, in an action stiffly opposed by Moscow, signed their own treaty of peace and friendship. That accord, formally ending hostilities that began in 1931, threatens to give rival Peking important leverage in tapping Japan's economic power as China undertakes a drive to become a modern industrial state. The Tokyo-Peking treaty contains an anti-hegemony" clause aimed at Moscow's own expanionist Asian intentions, triggering sharp Kremlin denunciations.

Formalizing what has long been a de facto relationship between the Soviet Union and Vietnam, thus sending a message to other Asian capitals of Soviet determination - and ability - to play a major role in the area. The treaty is accompanied by economic and technical aid programs bound to be watched with interest by the capital-poor emerging nations of the Pacific.

The treaty also may throw a crimp in moves by the Carter administration to resume diplomatic reations with Hanoi while at the same time trying for Hsiao-ping, visiting Thailand, called it "a military more difficult now," one Western source remarked.

The accord already has been denounced by Peking. On Tuesday, Chinese Vice Premier Teng Hsiao-Ping, visiting Thailand, called it "a military pact . . . of supreme importance to Asia and the Pacific because it is threatening security in the resionist schemese . . . The treaty does not contain a Asia."

Teng's attack was labeled "sheer concoction" by a Soviet government commentator, who asserted that "Peking regards a single, independent, socialist Vietnam as an obstacle to the attainment of its expansionist schemese . . . The treaty does not contain a single paragraphy which would affect the interests of any third country."

Moscow's anxieties about China run deep, welling from emotional ethnic, territorial and historic springs. But some are straightforward. For example, the Kremlin was alarmed when Britain and France indicated interest in selling advanced "defensive" weapons to China.

Moscow's worries over the Tokyo-Peking pact are in part economic. After years of costly effort, the Soviets are near major exploitation of natural resources in the Soviet far east and eastern Siberia. Difficulties with Japan have clouded once rosy notions of mammoth new Japanese markets and credit and now, through the Tokyo treaty, the Chinese have jumped into the picture in a big way.

Under the aging Kremlin leadership of Leonid Brezhnev, the Soviets for more than a decade have sought better ties along the Asian rim as a way of curbing Chinese influence.

These efforts increased after Japan normalized diplomatic relations with Peking in the early 1970s and the United States moved from "Ping-Pong diplomacy" to president Nixon's Peking visit and now a liaison office in the Chinese capital.

While Moscow once was suspicious and critical of the five-nation grouping of Indonesia, Malaysia, Thailand, Singapore and the Philippines, Soviet propaganda now speaks of developing better economic and cultural ties with the Association of Southeast Asian Nations.

The Kremlin has continued the low-profile approach in the smaller Asian nations while responding to real or imagined Chinese thrusts. Thus, the Soviets have been carefully "correct" with the isolationist Burmese government, while propagandizing about Chinese subversion in Burma's border regions.

In response to Chinese overtures to Thailand, the Soviets have tried for better relations with that Western-oriented nation, sending a top official to Bangkok for a visit. Laos, dominated by the Vietnamese, has not been a focal point of intense Soviet dilpomatic acitivity.

Aside from direct political counters to China in Southeast Asia, the Vietnam treaty has important ideological value to the Soviets in their convoluted struggle with Peking for dominance in the World Communist movement. It may enhance the Kremlin's image with some socialist and communist party factions outside Asia who long have been sympathetic with Vietnam.

Vietnam, recently admitted to full membership in Comecon, the East bloc economic community, may benefit from additional bilateral aid agreements with these countries.