The Soviet Union warned China tonight to withdraw its troops from Vietnam immediately or face unspecified serious consequences, the most severe warning to Peking since the invasion began.

Earlier today, Soviet President Leonid Brezhnev condemned China's invasion and called on Peking to remove its forces from Vietnam down to "the last soldier." But he stopped sort of outlining any countermeasures.

Brezhnev also spoke favorably of the prospects of a new strategic arms limitation treaty with the United States, indicating that Moscow is prepared to separate SALT from differences it may have with Washington over the Indochina war.

The government statement, made 2 1/2 hours after Brezhnev's speech, asserted that "Chin's aggression against Vietnam continues to expand" and charged that Chinese troops are being readied to invade Laos as well.

"Chinese troops must immediately withdraw outside Vietnam, military demonstrations on the borders of Laos and preparationa for invading that country must end," the official statement said. "The Chinese aggressors must know that the more crimes they perpetrate, the harsher will be the retribution."

Returning to the Soviet allegation that Western nations are encouraging the Chinese action, the statement added:

"The situation pressingly demands the unconditional and immediate and of the Chinese aggression, yet the governments of these states are precisely at this time taking new steps toward strengthening their contacts with China, including deals to sell it modern weapons."

Such a policy, it said, "is fraught with grave consequences and not in the least for those who conduct it."

There has benn widesparead speculation about what action, if any, Moscow would take on behalf of its ally, Vietnam. So far, Moscow has demonstrated its support by sending emergency airlifts of supplies, building up its Pacific fleet and issuing warnings to China.

Brezhnev's speech today was notably milder in tone than the later statement. The effect is to separate Brezhnev, putting him in a more conciliatory, statesmanlike pose which will allow him to address a variety of issues while the government concentrates on the Chinese crisis.

In an hour-long major speech cluminating the Communist Party electoral campaign for the Supreme Soviet, or national parliament, Brezhnev said SALT II is "now close to agreement." On completion of the treaty draft, "the new agreement probably will be signed during my meeting with President Carter, hopefully in the near future," he added.

Brezhnev's televised remarks were among the most optimistic he has made in months, underscording the view of Western experts that the Kremlin perceives SALT to be critical to detente.

Unlike other recent Soviet commentators, he neither accused Washington of complicity in the Chinese border invasion nor charged that "playing thr China card" threatens U.S. Soviet relations.

Six years of negotiations on SALT II, marked by frequent discord and tension since Carter took office, have now reduced differences on the complex issues and some American sources believe the Carter-Brezhnev summit could come next month.

Sources in Washington reported yesterday that Soviet Ambassador Anatoly Dobrynin, in talks this week with Carter and Secretay of State Cyros Vance, offered significant new ideas on remaining issues.

Brezhnev, who at 72 is in uncertain health, returned to Moscow this week after a month out of public view, reportedly vacationing on the Black Sea. At times during the speech, he spoke indistinctly, and occasionally lost his place. Shown walking, he stepped with a slight limp.

The president, who is also party leader, did not make any direct criticism of Carter, his foreign policy or performance on SALT.

"From our point of view, the treaty in some things could have been better," he said. "Not everything in it fully accords with our wishes. But that is a reasonable compromise which takes in the interests of both sides. On the whole, this is an important and good endeavor."

Brezhnev gave his immediate audience of voters from Moscow's Bauman district, which he represents in the Supreme Soviet, three reasons why he favors SALT "if it is signed, ratified and enters into force."

It will "create from several years a definite barrier to further stockpiling the most destructive and costly types of arms... it's implementation will not inflict any damage to the security of the Soviet Union or of the United States. On the whole, it will be advantageous to both countries."

It will "continue curbing the arms race," set the stage for follow-on SALT-III talks and "will probably help revive" talks on a comprehensive nuclear test ban, conventional arms sales and mutual force reductions in central Europe.

It will "undoubtedly have a beneficial effect on the international climate as a whole."

Brezhnev said he and Carter "intend to discuss alaos a number of questions of the further development of Soviet-American relations, consolidating the relaxation of international tension and strengthening universal peace."

It seems possible that this detailed addition of presumed SALT pluses may be aimed at curbing internal criticism of Soviet efforts on the pact.

Brezhnev said the conventional force reduction talks in Vienna "are bogged down in a quagmire of dispute" over counting soldiers "right to the last cook and medical orderly." Soviet and Warsaw Pact forces hold a wide numerical edge there, but he said the dispute is caused by the West.

Possible stationing of medium-range strategic missiles in West Germany, an issue now straining Bonn-Washington relations, "would result only in a new growth of tension in Europe," he said.

And he proposed a European pact banning first strikes of nuclear or conventional means, "something like a nonaggression pact."

Brezhnev also said the Soviets "welcome the victory" of the Iranian revolution for putting an end to "a despotic regime of opporession that had turned the country into an object of exploitation and a base of support for foreign imperialism."