Thai and Vietnamese troops battled for a second day along the Thai-Cambodian border, as tens of thousands of Thai villagers and Cambodian refugees huddled along highways and in rice paddies seeking safety from mortar and artillery shells.

Thai forces used F5 jet fighters, helicopter gunships and tank against Vietnamese positions while Thai long-range artillery kept up a steady barrage. By late afternoon, Vietnamese troops appeared to have withdrawn from the large refugee camps they overran yesterday but were continuing to shell Thai villages and military emplacements.

The two days of fighting have been the bloodiest confrontation ever between Thai and Vietnamese troops. Previously, there had been only minor skirmishes between the two.

[The Thai military command in Bangkok said that one of its helicopters and one of its light reconnaissance planes had been shot down near the border 140 miles east of Bangkok, the Associated Press reported.]

It was unclear whether Hanoi's troops had left Thai territory completely or were hanging on to a forest area close to the frontier. But at dusk, Thai forces moved new armor and men to forward positions as civilians lining the road cheered.

There were no firm figures on casualties. But about 50 civilians were being treated in one rear-area hospital alone. Red Cross medics and journalists helped evacuate dozens more from a roadside camp site aboue one mile from the border.

[In Bangkok, the Thai military said 21 of its soliders had been killed in today's fighting and that the bodies of 31 Vietnamese soldiers had been recovered, the AP reported. Western relief sources said an estimated 500 Cambodian and Thai civilians had bee wounded.]

The purpose of Vietnam's surprise incursion remained unclear. But relief workers evacuating wounded civilians genrally believe Hanoi wants to teach Thailand a "lesson" for supporting the Khmer Rouge guerrillas and the repatriation to Cambodia of approximately 5,000 soldiers and civilians.

Many analysts have said that the incursion may have been prompted by Thailand's decision to begin repatriating those refugees volunteering to go back from among the 150,000 refugees living in U.N.-sponsored camps deep inside Thailand.

Since last week, an estimated 6,000 people have returned to Cambodia, entering into zones along the border controlled by Khmer Rouge guerrillas loyal to the ousted Pol Pot government.

In late 1978, Vietnamese troops invaded Cambodia, overthrew the government of Pol Pot and installed Heng Samrin as head of the Cambodian government. The 1978 invasion caused the Khmer Rouge and anticommunist Khmer Serei ("Free Khmer") supporters to flee to the Thai-Cambodian border area.

In Bangkok, the Thai government delivered a note to the Vietnamese ambassador protesting the Vietnamese attack, news agencies reported.

[Thai Foreign Minister Siddhi Savetsila, in Kuala Lumpur, Malaysia for a meeting of the Association of Southeast Asian Nations], said Thailand was asking for a meeting of the U.N. Security Control on the incursion.

"I want to condemn their [the Vietnamese] violation and warn . . . about Vietnamese sweet talk . . . Their words cannot be relied upon," Siddhi told reporters.

[In Jakarta, Vietnamese Foreign Minister Nguyen Co Thach denied that Vietnamese troops had crossed into Thailand, Reuter reported.]

Fighting began early yesterday morning when Vietnamese troops captured two major border refugee camps run by Khmer Serei guerrillas. Refugees said some Khmer were marched into Cambodia but that the majority of the camps' approximately 80,000 people fled into Thailand.

Today the refugees were camping out on the dikes of flooded rice paddies and the shoulders of highways. Wounded were carried on hammocks strung on freshly cut branches, and children bathed in streams swollen by monsoon rains.

Thai troops barred the refugees from penetrating too deeply into Thai territory. One group of about 10,000 refugees was ordered to camp out in a wooded area and immediately began digging foxholes in case of shelling.

Refugees blamed many of the casualties on Thai shelling that followed the first Vietnamese advance, which apparently took its infantry to the outskirts of a village about one mile inside Thailand.

"If the Thais hadn't fired, no one would have been killed," said a young man who had fled a food distribution station run by foreign relief agencies at Nong Chan village where about 60,000 Khmers had gathered to pick up food rations to take back into Cambodia.

Thai villagers suffered casualties too. Villagers at None Mak Mun, about one mile from the border, awoke yesterday morning to find that about 500 vietnamese soldiers had entered the community during the night.

The Vietnamese brought a Laotian man who could speak the villagers' language with them. "They told us theywouldn't kill Thai civilians but that they were going to take our food supplies," one villager said.

Later in the day, Thai aircraft and infantry attacked None Mak Mun, and the Vietnamese withdrew. This morning the bodies of seven Vietnamese soldiers, dressed in olive-drab uniforms and canvas shoes, were dragged from the rice paddies outside the village.

Most Thai civilians joined the throngs of Khmer refugees seeking safety in fields and villages deeper inside Thailand. At least three villages were all but deserted, with houses and shops tightly shuttered.

During the day, Vietnamese gunners fired sporadically into Thailand. This correspondent and two other journalists were forced to take cover beneath a concrete bridge when about six mortar shell fell without warning on an intersection one mile inside Thailand.

Many analysts had expected Vietnamese forces to launch a major offensive to clear the border of the Khmer Rouge and Khmer Serei resistance groups at the onset of last autumn dry season. However, that offensive never materialized.

In the meantime, the area in which yesterday's fighting occurred became an active trading center, with Hanoi's forces allowing access in and out for Cambodian civilians and traders. Relief agencies opened a "land bridge" -- a route over which oxcarts could travel to pick up rice, seed and other badly needed supplies to carry into Cambodia.

The new attacks could signal Vietnam's intention to close the land bridge, which has never been officially recognized by the Hanoi government. The attacks also may be intended to disperse Khmer Serei guerrillas who live in the camps.