Three members of the 56-man U.S. military training team here were trapped in the naval base at La Union seaport when a column of guerrilla fighters staged a major attack on the town Saturday evening, the U.S. Embassy here said today.

An embassy official said the three men at La Union did not feel their safety was endangered and have not asked to be pulled out of the area.

It was the first time U.S. authorities have confirmed that U.S. advisers were at the scene of combat between the Salvadoran military and the leftist guerrilla forces seeking to overthrow the U.S.-backed government here.

The embassy would not identify the three advisers, who apparently were staying at the naval base when the attack began.

"We are not at liberty to confirm any details," an embassy official said, "but yes, we do have some of our trainers there. They are not allowed to be near areas of combat, but they were accidentally caught in this particular situation."

When U.S. military advisers were first sent to El Salvador, at the end of the Carter administration, critics of the program who expressed fears of "another Vietnam" were assured that the U.S. military men would stick to training and stay out of combat situations.

The official said the Salvadoran government had been "most cooperative," and a sizable force had been ordered by the Salvadoran Army to stay on alert in case it was necessary to evacuate the Americans.

Meanwhile, it was reported that fighting continued throughout the morning and early afternoon in the remote southeastern seaport on the Bay of Fonseca facing Honduras and Nicaragua. All telephone communications have been cut off since late last night.

A Defense Ministry spokesman, Col. Alfonso Cotto, said a mopping-up operation was under way in La Union, and he believed many of the guerrillas had withdrawn from the town yesterday afternoon.

La Union, 110 miles from here, is a town of 45,000 of some strategic importance both because of its shared territorial waters with Nicaragua and Honduras and because of the relative isolation of its four armed forces outposts, manned by the Navy, National Guard, National Police and Army.

The naval base, where the U.S. trainers are believed to be staying, faces the beach, near the three other garrisons. The guerrillas reportedly were being held back at the town church, a few hundred yards inland.

The guerrilla attack on La Union sent shock waves through the diplomatic community here and is believed to have taken the Army by surprise.

"We have all been watching the traditional guerrilla strongholds in the north and east of the country," said a Latin American diplomat. "No one expected them [the Farabundo Marti Liberation Front] to have any strength along the coast."

There has been speculation that the attack was launched from leftist-ruled Nicaragua, but at least two Salvadoran Army officers discounted that theory, saying they thought the attack was prepared in a guerrilla base on the nearby Conchagua Volcano. The Army has staged two "clean-up operations" on Conchagua involving heavy aerial bombardment, and pronounced the operations a complete success.

Most reports also agree that the guerrillas arrived in La Union by road, rather than by sea, as they would have if they had come from Nicaragua.

Given the strength of the guerrillas' attack, which reportedly lasted longer than any other attack on a major urban center since last January's failed offensive, it is thought that the rebles got at least some reinforcements from their mountain stronghold in the northeastern area of Morazan.

La Union, and the surrounding province of the same name, have not been highly organized by the guerrillas or by their nonmilitary "popular orgainzations," and it is unlikely that the Farabundo Marti Front, a coalition of five guerrilla groups, is attempting to set up a permanent base there.

Rather, observers here suggested, the attack may have been diversionary, designed to draw attention from a weapons landing further down the beach -- as U.S. diplomats have said -- or to ease pressure on the guerrillas in central El Salvador, who have been skirting a major mopping-up operation by the Army for the last six weeks.

Residents of La Union reached by phone last night, before the lines went dead, said they heard intense firing beginning at 7 p.m. Monday. A few said they had seen the guerrillas, who were well-armed and uniformed. The fighting continued unabated into the evening, when some reports indicate that the Army had started a house-to-house search operation.

The U.S. Embassy said it is monitoring the situation closely and that combat activity appeared to have eased by noon yesterday.

A representative of a French shipping company that has operations in La Union, however, attempted to reach the town early morning. He reported encountering no one on the desolate stretch of road from the nearest major town, San Miguel.He stood in the choking heat at the entrance of the town talking to a platoon of tense soldiers when the silence was broken by the sound of heavy gunfire.

"I listened for a while and then headed back to San Miguel," he said. "Only a fool would have stayed there."