For more than two years the United States depended on Honduran Gen. Gustavo Alvarez as a keystone in the elaborate structure of its clandestine war against Nicaragua's Marxist-led government. Yet when Alvarez was overthrown as commander of the Honduran armed forces and flown into exile on March 31, the CIA was surprised, according to U.S. intelligence and Foreign Service officers.

The Alvarez case is the most conspicuous of several such embarrassing intelligence failures dating back to the earliest days of the Reagan administration's efforts to "pressure" Nicaragua's government by supporting rebels fighting to overthrow it.

Washington had a lot of eggs in the general's basket. At the public level it had made an almost 20-fold increase in military assistance to the armed forces he commanded, from $4 million in loans in 1980 to $77.5 million in grants in 1984. In that same period, combined U.S.-Honduran military maneuvers on an unprecedented scale were a major tool in overt pressures against Nicaragua's Sandinistas.

But it was at the covert level that Alvarez was most important.

From the beginnings of U.S. involvement with the "secret war" in mid-1981 what was called a "tripartite" structure was put in place to run it. The United States supplied the money, Argentina supplied training and administrative skills (and initially a fig leaf to cover the U.S. involvement), and Honduras supplied the territory from which operations were mounted, according to U.S. intelligence sources and participants in the program.

A joint staff to manage and coordinate this program was created. The Nicaraguan rebel forces were represented by Enrique Bermudez and Emilio Echaverry, former Nicaraguan National Guard officers. Two Argentine colonels, Osvaldo Ribeiro and Santiago Villegas (also identified as Jose Ollas), represented their country. Alvarez represented Honduras. And the CIA station chief and one of his assistants represented the United States.

Alvarez was vital in this arrangement, not only because of his official position, but because of his longstanding personal ties to the others. He was educated at the Argentine military academy, where one of his classmates was Echaverry and one of his professors was Ribeiro, according to intelligence sources.

Alvarez also became personally close to the CIA station chief who arrived in the Honduran capital in the fall of 1982, several intelligence sources said. By one account, Alvarez became the godfather of the station chief's child.

In the months before his ouster, there was growing friction between the politically ambitious Alvarez and President Roberto Suazo Cordova, on one hand, and between Alvarez and officers whom he excoriated as incompetent in front of their peers, on the other.

"He was a very violent, aggressive personality," one senior Honduran colonel said in a recent interview. "Nobody was ever so rude and offensive with the officers." He described the coup against Alvarez by some of the officers he offended as a reflection of discontent that was "very great. There was not much opposition to the move, nor doubts."

U.S. Ambassador to Honduras John D. Negroponte said in an interview last summer that he had no advance warning of the move against Alvarez, and since then he has attempted to play down the relative importance of Alvarez and of the failure to anticipate his ouster.

U.S. intelligence officers, defensive about the failure to anticipate the general's removal, argue that it was plotted by a handful of officers with whom they had little contact and that there was no groundswell of opposition to Alvarez evident before he was removed at gunpoint from his command.

However, at least two of the Honduran officers, including Air Force Gen. Walter Lopez, who is now commander of the armed forces, had frequent contact with the embassy, according to intelligence sources. The problem, these sources said, was that they viewed the embassy as so close to Alvarez that they had not the slightest intention of telling anyone there about the plot.

After Alvarez was removed, the new commanding officers "wouldn't talk to anybody" at the CIA station in the Honduran capital, one diplomat familiar with the case said. "They were coldly detached. They saw that the CIA station chief and the gang were protectors, creators and personal friends of Alvarez, and they didn't want to talk to them."

Vital training and logistical facilities for the anti-Sandinista rebels were shut down or moved to more remote locations within weeks. Before Alvarez was thrown out, the United States had saved money and circumvented limits on the numbers of U.S. advisers in El Salvador by training Salvadoran units in Honduras. Alvarez's successors put an end to that.

As a result of this intelligence fiasco the station chief, whose name is well known in Honduran military and diplomatic circles, was transferred to another assignment in June.

Suspicions linger among Honduran officals, according to diplomats there, that Alvarez could use the contra forces to help him return to power. Alvarez, now living in Miami, could not be reached for comment.