Heavily armed Iranian guerrillas attacked the American Embassy here today, killing an Iranian employe and wounding a U.S. marine in nearly two hours of intense shooting.

Under siege in the chancery building inside a walled compound in central Tehran, embassy personnel destroyed classified files, code gear and some electronic equipment before armed men loyal to religious leader Ayatollah Ruhollah Khomeini intervened to stop the guerrilla attack and rescued embassy staffers.

The attackers, apparently Marxist guerrillas of the Cherikhaye Fedaye Khalq (People's Sacrifice Guerrillas) organization, ransacked parts of the embassy building after blasting it with heavy automatic weapons fire in a well organized and unprovoked assault.

Los Angeles Times correspondent Ken Freed and I were inside the embassy when the attack began. Trapped by fierce firing, we were eventually marched out of the building at gunpoint, hands overhead, along with embassy staffers when the mission was captured by guerrillas.

Tonight, the national radio and television reported that it was under attack by unidentified gunmen and broadcast an appeal for armed Khomeini supporters to come to the rescue. A later broadcast said the attackers were beaten back.

Iranian officials also said several hundred persons had been killed in fighting in Tabriz, about 330 miles northwest of here. Although accounts of the clashes there were conflicting, today's incidents may signal a brewing confrontation between conservative Khomeini supporters and leftist radicals.

Three guerrillas were reported killed in the embassy battle, presumably when pro-Khomeini militiamen arrived and clashed briefly with the attackers.

The U.S. marines defended the embassy by firing tear gas and then shotguns loaded with number nine skeet shot. The shot is rarely lethal, the embassy army attache said, and it was used to wound rather than kill the attackers.

The wounded marine was shot with his own shotgun at close range after had surrendered to the attacking guerrillas.

An Iranian waiter at the embassy restaurant was killed when he was shot in the chest after coming out to surrender to the attackers, embassy officials said.

The Fedaye issued a statement denying responsibility for the attack. But several of the guerrillas who penetrated the embassy compound and captured personnel admitted they belong to the organization. European diplomatic sources who watched the battle also identified them as such.

The sources said the guerrillas started the battle by opening fire on the embassy from surrounding rooftops, after blocking off the street in front of the compound's main entrance.

Throughout the ordeal, Ambassador William Sullivan personally directed the defense of the embassy. Issuing orders to marine guards via walkie talkie, he urged restraint in an apparent effort to avoid a potential massacre when the guerrillas' superior numbers and firepower won out.

The marines also acted coolly underfire, keeping the attackers at bay until forced to surrender to them.

The new "provisional government" installed by Khomeini had no official explanation for the attack. But the semiofficial version given by Khomeini representatives who arrived at the scene after the shooting had been going on for more than an hour and a half blamed agents of the disbanded secret police, SAVAK.

These representatives claimed variously that SAVAK agents had taken refuge in the embassy compound and were shooting at people outside, provoking the intervention of guerrillas, or that the agents mounted the attack from the outside themselves and were only driven away by the guerrilla rescuers.

Obviously embarrassed by the whole episode, however, the Khomeini authorities could not conceal the fact that they are as yet unable to control Marxist guerrillas, who, by attacking the embassy, defied a Khomeini order against such actions.

Here is a chronological account of what happened at the embassy today:

The Iranian army having been with-drawn to barracks Sunday, the embassy was guarded by its normal contigent of 19 marine guards wearing battle fatigues and flak jackets because of frequent sniping in recent days.

While Freed and I were in a temporary consular office in the west wing of the embassy, we heard shots ring out but did not think it unusual under the circumstances. Then the fire quickly escalated and we took cover. At about 10:30 a staffer turned on his walkie talkie and we heard a marine shout that four armed men had climbed over the wall into the compound.

Snipes pinned down the marines as more guerrillas came in.

Ambassador Sullivan, in his second floor office, came on the radio using the codename "cowboy" and gave a marine permission to use tear gas.

Heavy incoming fire continued, with the marines exercising restraint.

At 10:57 the ambassador was asked by the marines for permission to fire, and he said, "If you need to protect yourselves, you may fire. If you can arrange to surrender, do so."

Meanwhile other marines tried to get through a door of the ambassador's residence and take servants out.

At 11:25 one marine position announced it was surrendering. An aide in the ambassador's office repeated the instruction: "If you can make contact with them (the guerrillas), tell them we will not resist. Surrender any place you come in contact with them."

Nevertheless the shooting -- with automatic rifles, submachine guns and 30-calibre heavy machine guns -- continued, and the guerrillas assaulted the east wing of the embassy. In response, the marines tear-gassed the east corridor.

Suddenly a marine barked, "They're in the building," and the ambassador ordered him to surrender. Dejectedly he replied, "Aye Aye sir."

Then came the order: "Destroy all equipment. Destroy everything."

At 11:37 the voice of one beleaguered marine came over the walkie talkie: "How can I surrender? There's too many people around me shooting. How can I surrender?"

Shouts in Persian were now clearly audible immediately outside the chancery's steel-shuttered windows. The radio crackled that about 200 people were coming in the main gate, and everyone was ordered upstairs.

As bullets smacked into outside walls and through windows, we ran down the hall to the main lobby and up the stairs to the second floor. There we sat in a hallway as Marines tear-gassed the lower corridors and locked a metal door to the stairs.

As the attackers stormed the building and the tear gas fumes seeped under the door, about a hundred of us were ordered into a vault sealing a room filled with communications equipment where staffers were busily shredding and burning classified documents in priority order.

At 11:49 cheers went up when the word came over the walkie talkie that Khomeini's armed men had arrived and that there was some shooting outside between the rescuers and the attackers. We were also told that Khomeini men were talking to the guerrillas with bullhorns and telling them not to shoot.

Somebody said, "Happy Valentine's Day, folks," and a few marines inside the vault with us passed out cigarettes and cold beers from a nearby refrigerator.

An embassy staffer used a sledgehammer to smash sensitive communications equipment in an adjacent room, then pulverized several cryptographic code plates. The marines were ordered to discard weapons and ammunition.

While this was going on, the attackers succeeded in breaking into the top floor, and the ambassador arranged a surrender.

We were ordered to file out of the vault with hands held high. A guerrilla armed with a submachine gunrushed by us into the communications room shouting excitedly in Persian. Others frisked us every few paces.

With shooting continuing outside, we were herded into the ambassador's outer office. By this time Khomeini militiamen had also entered the building and were trying to calm down the attacking guerrillas.

One bearded, bayonet-wielding young man from the Khomeini committee conferred with Sullivan, their arms around each other's shoulders.

Then heavy shooting suddenly resumed outside and everyone hit the floor. The attackers still seemed to be in control. One excited gunman, convinced we were withholding weapons, fired his Iranian-made G3 automatic rifle into the ceiling, while others tried to blast open a vault with gunfire.

Then we were herded out, frisked again and led down the stairs and out a side door with our hands up. There Khomeini loyalists with "Islamic army" written on armbands seemed to be in charge, assuring us, "You are our brothers. Don't worry."

They mingled with other guerrillas who had apparently carried out the attack. A few of them acknowledged they were members of the Fedaye, a Marxist guerrilla group with links to radical Palestinian organizations.

A number of the guerrillas wore masks. including one who carried a heavy machine gun in his arms.

Periodic shooting could still be heard in the compound and surrounding area, and the two sides argued heatedly over who was in command.

Ibraham Yazdi, an American-educated Khomeini aide just named deputy prime minister for revolutionary affairs in the new cabinet, pleaded with the guerrillas in the name of Islam to leave the premises. He condemned the attack, saying it hurt the prestige of the "Iranian revolution" and threatened to lower international respect for the new regime.

Shortly afterward we were escorted around to an area near the ambassador's bullet-riddled residence and later released.

After meeting with several mullahs who arrived to restore order on behalf of Khomeni, Ambassador Sullivan called the incident "a very heavy attack by well-equipped and well-armed men who came in over three sides of the compound." He declined to say which group he thought was responsible.

"We telephoned the Khomeini group and they came in and saved us in a nick of time," Sullivan told reporters.

The "Islamic army's" guards remained on the compound to protect the embassy against any other attacks.