Vietnam said Tuesday night that it would agree to talks with China on improving relations if Chinese troops carry out their announced plans to withdraw from Vietnamese soil.

The statement by a Vietnamese Foreign Ministry spokesman was broadeast by Radio Hanoi and was Vietnam's first official reaction to Peking's announcement Monday night of a troop withdrawal and the first positive responese to repeated Chinese appeals for negotiations since the Sino-Vietnamese border war began Feb. 17.

Although Western analysts said there still appeared to be some fighting or at least shelling along the Chinese invasion front, the Vietnamese statement reduced fears that Hanoi might order an attack on the retreating Chinese troops and force the Chinese to retaliate.

[Vietnam said Wednesday its troops would allow China to pull out its 100,000-man invasion force without military opposition, according to news service reports of an article in the official Communist newspaper, Nhan Dan. Hanoi claimed victory and said Vietnamese forces inflicted "heavy casualties on the invasion troops.]

An authoritative Chinese statement, scheduled to be published Wednesday morning in Peking's People's Daily but released Tuesday night by the Chinese, declared the "glorious counterattack in self-defense" a "complete success." It congratulated the Chinese troops for their "dauntless revolutionary heroism" and warned the Vietnamese against any future border violations.

There is some evidence that some Chinese troops may have withdrawn even before Tuesday night's Peking announcement. But the Chinese have not said how long a total withdrawal will take.

Analysts said an important victory by Chinese troops over the Vietnmanese at the provincial capital of Lang Son appeared to satisfy Peking that it had punished Hanoi and convinced Vietnam's ally, the Soviet Union, of China's military resolve.

Vietnam's offical news agency continued to warn Tuesday that the Chinese were planning to expand the war into Laos and repeated Monday's order for a general mobilization in which all eligible persons would be required to join the armed forces. The Radio Hanoi statement Tuesday night said that if the Chinese withdrawal proved a "trick," the mobilization would proceed.

The Vietnamese spokesman said that once the Chinese withdrawal was complete, negotiations at a time and place to be agreed on could begin at the vice foreign minister level to discuss restoration of normal relations.

China invaded Vietnam 18 days ago after a year of charges of border violations and bloody skirmishes from both sides. Chinese and Vietnamese vice foreign ministers had a series of talks from Aug. 8 to Sept. 26 in Hanoi last year. Peking broke off the negotiday, calling for talks at the vice foreign minister level, spoke of the need to "settle for disputes concerning the boundary and territory.

Tuesday's Hanoi statement and previous Vietnamese reports have not recognized any dispute over the location of the border, and Western diplomats have not found any record of such a dispute.

The Vietnamese statement Tuesday said the Chinese had committed "gross aggression" with half a million troops and that China had been forced to announce the withdrawal. Western analysts put the total number of Chinese troops involved in the operation at about 250,000. About 100,000 of those are said to have crossed the border on a wide front that at one point went as deep as 25 miles into Vietnam.

China has not said how many Vietnamese casualties it has inflicted or how many of its own troops have been killed or wounded. Vietnam has reported more than 45,000 Chinese casualties through yesterday, although Western analysts consider that figure greatly exaggerated.

Vietnam has rejected previous Chinese offers to begin talks on the grounds that no negotiations were possible until the Chinese invasion ended.

Radio Hanoi said fighting continued Monday in at least three areas of the front. It said "hundreds" of Chinese troops were killed or wounded in the area of Lang Son, 12 miles inside Vietnam, Monday. Western analysts said Chinese troops smashed a heavily reinforced and armed Vietnamese force there after week-long battles on the hills that surround the town.

Radio Hanoi said a Chinese battalion was "badly trounced" in Cao Bang Province Monday and that the Chinese suffered 640 casualties in northwestern Hoang Lien Son Province. Vietnam has so far not reported its own casualties.

Statements by Chinese leaders have indicated they launched the invasion in part to prove to Vietnam, and more importantly to the Soviet Union, that China was not militarily weak or indecisive. Peking announced from the start, however, that the invasion would be limited in time and scope.

Moscow has airlifted supplies to Hanoi during the conflict and stationed eight or nine ships for apparent surveillance off the Vietnamese coast, but apparently made no other provocative moves.

The Japanese Defense Agency said Tuesday that a Soviet landing ship and a missile destroyer had steamed into the South China Sea, perhaps to join the small Soviet task force already engaged in watching the war. The agency said it did not know what the 4,100-ton Alligator-class landing ship was carrying, but that it had the capacity for 1,700 tons of cargo or 300 troops and 30 tanks.

Some earlier official Chinese news agency reports had hinted that Chinese troops might remain in some border territory previously held by Vietnam which Peking considers part of China. But the People's Daily editorial said: "Out frontier forces are now victoriously returning to their original positions."

The war, said a People's Daily editorial released today, "exploded the myth of the invincibility of this 'Asian Cuba' and dealt a telling blow to the Soviet Union's scheme for aggression and expansion in Sourtheast Asia."

It repeated Chinese objections to the presence of 100,000 Vietnamese troops in Cambodia, where a pro-Peking government was forced out of power in early January and has had to resort since to guerrilla attacks on the Vietnamese. "The Vietnamese aggressor troops must completely pull out of Kampuchea" (Cambodia), the editorial said, but it did not tie thid demand to the negotiations it is seeking with Hanoi.

Both the Chinese editorial and the Radio Hanoi statement Tuesday night expressed friendship for the people across the border and an eagerness for peace.