Late last year, President Reagan approved a covert operation directing the Central Intelligence Agency to train and support several counterterrorist units for strikes against suspected terrorists before they could attack U.S. facilities in the Middle East, according to informed sources.

About four months later, members of one of those units, composed of Lebanese intelligence personnel and other foreigners, acting without CIA authorization, went out on a runaway mission and hired others in Lebanon to detonate a massive car bomb outside the Beirut residence of a militant Shiite leader believed to be behind terrorist attacks on U.S. installations, the sources said.

More than 80 persons were killed and 200 wounded in the car bombing in a Beirut suburb on March 8. The suspected terrorist leader escaped injury.

Faced with an indirect connection to the car bombing, alarmed CIA and Reagan administration officials quickly canceled the entire covert support operation, the sources said.

CIA personnel had no contact with those who actually carried out the car bombing, they said. According to one source, officials of the intelligence agency were upset that one of its most secret and much debated operations had gone astray.

Administration spokesmen had no comment yesterday.

Several intelligence sources said the incident revealed the hazards of trying to fight the "dirty" war of terrorism. Others questioned whether training and support of the covert units might have violated the longstanding prohibition against U.S. involvement in assassinations. One source, skeptical of the short-lived operation, called it "an illustration of how some people learn things the hard way."

Another source said Defense Department officials refused two years ago to give Lebanese units any counterterrorism training because of fears that "we'd end up with hit teams over there . . . . The concern was that when some have the capability, it can be turned upside down and used offensively. The concern was that one faction would use it on the other factions."

Administration sources said that the congressional oversight committees on intelligence were briefed on the covert support operation in Lebanon after the president approved it late last year, although Reagan specifically directed that only the chairmen and vice chairmen of the Senate and House intelligence committees be informed.

Several sources said there is some question whether the new chairmen and vice chairmen who took over the committees in both chambers in January received full briefings on the operation. Administration sources last week insisted that they had.

Within weeks of the March 8 car bombing and the cancellation of the covert operation in Lebanon, both Robert C. McFarlane, the president's national security affairs adviser, and CIA Director William J. Casey gave speeches saying the administration had the capability to preempt terrorist attacks.

Using the same language, both McFarlane and Casey said: "We cannot and will not abstain from forcible action to prevent, preempt or respond to terrorist acts where conditions merit the use of force. Many countries, including the United States, have the specific forces and capabilities we need to carry out operations against terrorist groups."

It could not be learned exactly what capabilities McFarlane and Casey were talking about. The CIA has extensive worldwide counterterrorist training operations designed to help other nations defend against and react to terrorist attacks. McFarlane and Casey have declined to elaborate. McFarlane's speech was given here on March 25 and Casey's in Cambridge, Mass., on April 17.

Dozens of bystanders were killed and wounded in the March 8 car bombing in a Beirut suburb about 50 yards from the residence of Mohammed Hussein Fadlallah, leader of the Hezballah (Party of God), a militant Shiite movement. A number of Fadlallah's bodyguards reportedly were killed in the explosion.

No one publicly has claimed responsibility for the bombing. Some Shiites accused the Israelis, who denied any involvement.

Numerous U.S. intelligence reports have tied Fadlallah directly to the series of terrorist attacks on American facilities in Lebanon in 1983 and 1984. According to one report, Fadlallah participated in an Oct. 20, 1983, planning meeting of terrorists in Damascus, Syria, three days before the suicide bombing of the Marine headquarters compound in Beirut that killed 241 U.S. servicemen. Intelligence reports also say that on the night of Oct. 22, 1983, just hours before the bombing, Fadlallah received and blessed the man who drove the truck carrying the explosives in the suicide bombing.

Fadlallah's group also was responsible for the more recent Sept. 20, 1984, bombing of the U.S. Embassy annex in Beirut, according to intelligence sources. Fadlallah has denied involvement in these terrorist actions.

A Lebanese intelligence source said: "My service did the March 8 Fadlallah bombing. I believe it was done to show we are strong . . . . You've got to stop terrorism with terrorism."

The Lebanese source said that the CIA would have nothing to do with a car bomb because of the danger to innocent people. But the source contended that the CIA knew it was being planned.

U.S. sources emphatically denied any advance knowledge of the bombing and said immediate steps were taken after it occurred to cancel the entire covert operation.

The plan to form and train three teams of Lebanese capable of neutralizing or disabling terrorists before they could make planned atacks on American targets was approved after years of internal debate and increasingly tough Reagan administration rhetoric about how to respond to the wave of devastating terrorist attacks abroad. Preemptive Strikes Difficult

The covert training and support program was set up under a presidential "finding" signed by Reagan. It specified that the teams of foreigners were to be used only with great care and only in situations where the United States had good intelligence that a terrorist group was about to strike. The teams were supposed to use the minimal force necessary to stop specific attacks. Several sources said this included the authority to kill suspected terrorists if that was the only alternative.

Conducting preemptive strikes is very difficult in practice, because they depend on intelligence information that is timely and accurate. However, sources said the U.S. capability to collect advance information on planned terrorist actions is improving.

After previous terrorist attacks on American facilities in the Middle East, U.S. officials learned they had had some clues, at times significant ones, before the event. But they were only discovered afterward, when analysts sorted through raw intelligence reports, communications intercepts and satellite photography.

Officials said the short-lived covert operation in Lebanon did not violate the presidential ban on involvement of U.S. personnel, directly or indirectly, in any type of assassination planning or operation. The prohibition dates to 1976, after congressional investigations uncovered such plots against Cuban President Fidel Castro and other foreign leaders.

Reagan administration officials reasoned that killing terrorists was "preemptive self-defense" rather than assassination, according to one source, who said, "Knocking off a guy who is about to kill you is no more assassination than a policeman getting off the first shot at a man pointing a shotgun at him."

Secretary of State George P. Shultz and national security affairs adviser McFarlane were chief proponents of the covert plan in Lebanon, sources said. Shultz Urged Response

"State and the White House pushed this," one source said. According to this source, the final decision to approve the plan late last fall was made because of "Shultz's assertiveness and Defense Secretary Caspar W. Weinberger's reluctance to use force conventionally, and McFarlane's anger with terrorism."

Sources said that McFarlane was instrumental in developing a consensus from the disparate views of senior administration officials.

Shultz repeatedly has urged a strong response to terrorism, which he has called "barbarism that threatens the very foundations of civilized life." On the other hand, Weinberger has voiced reluctance to use military force without full public support.

Sources said that some senior intelligence officials opposed involving the intelligence agencies in what one official called "the ultimate covert action: an undercover hit squad." The revelations of previous assassination plots and the more recent public and congressional criticism of the CIA's involvement in a covert war against the leftist Sandinista government in Nicaragua made the CIA reluctant to undertake new operations, according to the sources.

The covert option was selected, the sources said, as a preferable alternative to the use of military force such as the guns of the battleship New Jersey or air strikes, which could kill or injure innocent civilians close to a terrorist camp.

The sources also said that training and supporting a covert team would avoid the possibility of live television coverage of U.S. military action and the visible use of American force in the Middle East, which previously had increased anti-American sentiment and more acts of terrorism. Compared with the alternatives, the sources said, a small team also would be the most cost-effective.

Two weeks after the unauthorized March 8 Beirut car bombing aimed at Fadlallah, McFarlane gave his speech that seemed to confirm the existence of some type of new counterterrorist capability. McFarlane said that in making a decision to react, "we need not insist on absolute evidence that the targets were used solely to support terrorism."

In his speech, "Terrorism and the Future of Free Society," McFarlane said he was outlining the "operating principles" of a presidential directive on terrorism. "Whenever we obtain evidence that an act of terrorism is about to be mounted against us, we have a responsibility to take measures to protect our citizens, property and interests," McFarlane said.

"Use of force in self-defense is legitimate under international law," he said. "It is explicitly sanctioned under Article 51 of the United Nations charter."

Sources said this speech and one given by Shultz on Dec. 9 in New York, "The Ethics of Power," were intended to express the rationale for administration policy.

Addressing an audience at Yeshiva University, Shultz said: "The Talmud upholds the universal law of self-defense, saying, 'If one comes to kill you, make haste and kill him first.' Clearly, as long as threats exist, law-abiding nations have the right and indeed the duty to protect themselves."

According to the sources, Reagan approved the covert "finding" authorizing CIA training and support for antiterrorist units in Lebanon just before Shultz gave the speech last December. Mock-Up of Embassy Seen

Two sources said that the Sept. 20 terrorist bombing of the U.S. Embassy annex in Beirut last year helped persuade officials that they had to develop some means of preempting planned terrorist attacks. After the fact, officials learned that U.S. intelligence agencies had overhead satellite photographs of what is thought to be the van used in the suicide bombing.

Those photos showed the vehicle outside a mock-up of the embassy annex that the terrorists were using for a practice run, sources said. Although the connection was established after the fact, the sources said that, in the future, this kind of intelligence might be part of the basis for a preemptive attack.

One source argued that the decision to use a covert team amounted to recreating for the CIA a role it played in its early years, before the Watergate scandal and subsequent congressional investigations of the agency dampened its ardor for clandestine operations.

Accordingly, this source said, Reagan's decision to authorize the covert team was "the final curtain on the legacy of both Vietnam and Watergate." Of all the Reagan administration's decisions on national security, this source said, "It was the most tricky, the most controversial and sensitive . . . . It took the most goading to get change."

But when the operation went astray after the Lebanese went ahead with an unapproved car-bombing, officials involved in the plan felt they had no alternative to canceling U.S. support for the antiterrorist squads.

One official who favored creation of the units said: "If you take terrorism seriously, as we must, you've got to realize that it could get worse . . . . If we had information on some terrorists involved in nuclear detonation practice, you've got to act.

"No choice. That is the type of issue we are going to have to face, and we better be ready."