Invading Chinese troops appeared to be continuing attacks four to six miles within Vietnamese territory Sunday but Peking promised a pullback after punishing Hanoi "as much as is necessary."

Radio Hanoi said Vietnamese Army and militia forces had "put out of action thousands" of Chinese troops and destroyed or set on fire nearly 60 tanks since the Chinese invasion began Saturday morning. It said the heaviest fighting was in the Batxat, Kaokay and Muongkhuong areas of the northwest and the Dongdang and Nghi areas of the northeast.

The radio said many Chinese units were encircled and heavily engaged. But the official New China News Agency said late Sunday night that the Chinese "counterattack" was "continuing."

The Soviet Union, whose intervention could give the Sino-Vietnamese border war global importance, bitterly denounced the Chinese invasion. It said it "will honor its obligation" under a recent treaty with Vietnam which calls for mutual aid in case of attack. Some foreign diplomats said they thought Peking would assess the Soviet threat and pull out of Vietnam before Moscow could intervene.

A front-page editorial in Peking's official People's Daily said Sunday, "After hitting back at the [Vietnamese] aggressors as much as is necessary, our frontier forces will turn to guard strictly the frontier of our motherland." Some diplomats in the Chinese capital interpreted the wording of the editorial to indicate the limited offensive would end shortly.

Vietnamese Premier Pham Van Dong signed in Cambodia a treaty of peace, friendship and cooperation Sunday with the Cambodian government of Heng Samrin, whom Hanoi installed in Phnom Penh last month after ousting a group backed by Peking. The treaty is expected to solidify Vietnam's effective control over its small neighbor, where guerrilla warfare is still raging between pro-Hanoi and pro-Peking forces.

Diplomatic and military sources here and in Bangkok said mostly militia were defending Vietnam's border area. It was not clear if regular Vietnamese Army units stationed near Hanoi and Haiphong had yet moved up to engage the Chinese. Foreign analysts said the overwhelming Chinese force was capable of striking Hanoi and Haiphong, but was expected to try instead to cripple Vietnamese units it engaged across the border, and then withdraw.

The Vietnamese Army newspaper Quandoi Nhandan said Vietnamese forces were checking the Chinese advance. Analysts here and in Bangkok said they could not confirm this, but suggested the Chinese may be consolidating positions just inside the border to await Vietnamese and Soviet reaction.

The Vietnam News Agency indicated the main areas of fighting were in Caobang and Langson Provices in the Vietnam's northeast and Hoanglienson Province in the northwest.

A message from Vietnamese Foreign Minister Nguyen Duy Trinh to U.N. Secretary General Kurt Waldheim said the Chinese have occupied Vietnamese border posts and many villages in Trangdinh, Locbinh and Vanlang Districts in Langson province, Tralinh and Haquang in Caobang Province, Muongkhuong and Batxat in Hoanglien Province, Phongtho in Laichau Province and Binhlieu in Quangninh Province."

He said the provincial capital of Laocai and the townships of Dongdang and Muongkhuong, about six miles inside Vietnamese territory, had been occupied.

A Vietnamese report said the Chinese "wantonly fired long-range artillery on provincial and district towns, densely populated areas and villages to pave the way for their armor and infantry to strike deep into Vietnamese territory."

The Vietnamese indicated fighting was particularly heavy in the Bangquang area of Hoanglienson, where 250 Chinese troops were "wiped out and four tanks set on fire." In the Friendship Gate area of northeast Vietnam, where Chinese had reported unusually heavy Vietnamese fortifications and laying of explosives, eight Chinese tanks were destroyed, the Vietnam News Agency said.

The first official Chinese report on the fighting since its midnight Saturday announcement of the "counterattack" did not come until about midnight Sunday. The three-paragraph report gave no details of the fighting inside Vietnam. Instead, it reported Vietnamese strafing of Hekou and Jinping on the Chinese side of the border in Yunnan Province early Saturday morning and a 1,200-shell Vietnamese bombardment of a railway station, schools and a rubber plantation in Hekou on Saturday afternoon.

The People's Daily editorial said China needs peace and stability for its modernization program and can not tolerate further border harassment by Vietnam.

"The trees may prefer calm but the wind will not subside," the editorial said. "Under the instigation and support of Soviet social-imperialism, the Vietnamese authorities escalated their armed encroachment upon China, which has reached an intolerable dimension, compelling us to take an action which we were unwilling to take."

The Chinese statement issued Saturday night called on Hanoi to agree to negotiations to solve the border crisis, although China last year pulled out of negotiations on the persecution of ethnic Chinese in Vietnam, one cause of the falling out between the former socialist allies.

Military analysts called the Chinese invasion a "totally conventional" military exercise with troops supported by tanks, artillery and aircraft moving along the major roads and rail lines. An estimated 160,000 to 200,000 Chinese troops are in the vicinity of the Vietnamese border, although it is not known how many have crossed into Vietnam.

According to the International Institute for Strategic Studies, China boasts armed forces totaling nearly 4 million men, including a 3.2 millionman Army divided into 12 armored divisions, 121 infantry divisions, 40 artillery divisions, 15 engineering divisons, three airborne divisions and 150 independent regiments.

Vietnam is thought to have elements of 20 divisions, totaling from 100,000 to 200,000 men, in Cambodia, and another two divisions in Laos. Some sources said this left only an estimated three divisions totaling no more than 30,000 men in the Hanoi-Haiphong area.

More detached regiments are deployed throughout Vietnam and could be sent to the border area. Analysts said they thought one objective of the Chinese attack was to draw Vietnamese troops away from Cambodia and thus improve the morale of the pro-Peking forces there, who have lost control of the government but are still fighting the Vietnamese.

The Vietnamese Army is estimated to total about 600,000 men in 25 infantry divisions, a 10-regiment artillery command, an engineering command and a number of independent regiments of infantry, antiaircraft and surface-to-air missile batteries and engineering units.

Despite the movement of several squadrons of Chinese F9 fighters and of Vietnamese Phantom jets to the border area recently, diplomatic sources here and in Bangkok said there appeared to have been few if any air engagements. Chinese jets were reportedly bombing and strafing only near the border, and Vietnamese jets had not yet challenged them in any significant numbers.

Foreign analysts said they remained puzzled by the Chinese decision to attack. The loss of weapons and manpower and criticism of Peking abroad appeared to them to outweigh any advantage the Chinese might gain from the action.

The Chinese appeared to want to put Vietnamese forces through a "meat grinder," one source said, but did not appear to have much time to do it if they wish to avoid Soviet intervention.