A U.S. military officer was visiting a Salvadoran Army battalion deep inside territory that usually is controlled by left-wing guerrillas when the unit came under fire, the U.S. Embassy said today.

The incident occurred last Friday, the same day two other U.S. military officers and two civilian embassy officials also visited the battalion, but they departed by helicopter before the guerrillas began shooting, the embassy said. Nobody was known to have been injured in the 20-minute firefight, it said.

U.S. Embassy guidelines prohibit U.S. personnel from traveling to areas where combat is likely, but the embassy said the five U.S. personnel had not broken the rules. Before making the trip, the U.S. officials "judged that combat was not likely to occur," an embassy spokesman said.

The U.S. personnel visited the U.S.-trained Arce Battalion while it was occupying the mountain village of Perquin in northeastern El Salvador. Perquin informally is considered the left-wing guerrillas' "capital" because it normally is the headquarters of one of the two main factions of the Farabundo Marti National Liberation Front.

The embassy did not issue a formal statement on the incident until reporters learned of it and began asking questions.

The U.S. military officer present during the skirmish is in the defense attache's office at the embassy. He took cover but did not return fire, the embassy said. U.S. military officials are permitted to carry a shortened version of the U.S. Army's standard M16 automatic rifle in the field.

Several U.S. citizens, wearing military uniforms and carrying automatic rifles, also were present in Perquin during the firefight. But the embassy said that they were "action journalists" from Soldier of Fortune magazine.

"They are in no way employed or connected with the U.S. government, nor are they acting at the request of the U.S. government," an embassy statement said.

Soldier of Fortune has every appearance of being a magazine for mercenaries, although it bills itself as a journal for "professional adventurers." Former U.S. military personnel associated with the magazine have helped train Salvadoran units and traveled with them in the field.

The Reagan administration fixed the number of U.S. military advisers in El Salvador at 55 in 1981 and since then has restricted their activities so that they would not end up fighting in the civil war here.