A hesitant consensus appears to be growing in the Reagan administration and Congress that the effort to preserve a democratic state in El Salvador is succeeding.

The five-year-old Salvadoran civil war has cost nearly 50,000 lives. Fighting and human rights abuses on both sides continue. U.S. aid to the Salvadoran government has totaled nearly $2 billion since 1981, and it will have to continue at high levels for the foreseeable future. El Salvador's economy is shaky, the political extremes, though weakened, continue to operate, and 20 percent of the population has fled their homes.

But many in Washington, including early skeptics about democracy's prospects in El Salvador, now say that although the price has been heavy, democratic institutions have taken a tentative hold in the country, and are gathering strength. If that trend continues in the face of formidable obstacles, it could lead to a negotiated political settlement and an end to the war.

Such an outcome still seems remote, but it appears more likely now to dozens of policy makers interviewed than does a military outcome.

This tentative verdict has major implications for U.S. policy toward other nations where leftist rebellions threaten noncommunist governments. The elements in the United States and in El Salvador that combined in a promising chemistry are being studied closely in the hope of finding guidelines for promoting democratic institutions worldwide.

One general point of agreement is that credit for any progress should go, not to the Reagan administration alone nor to Congress alone, but to a long and tortuous process of debate and compromise that produced a hybrid U.S. policy -- a policy nobody had intended and few people liked.

Where the administration pressed for unfettered military aid to El Salvador's government, liberal members of Congress opposed helping a repressive, bloody and corrupt regime in the face of an uprising that had popular roots. What emerged was reduced aid tied to improvements in human rights, land reform and elections, a flawed compromise that irritated everyone but that seems to have worked.

It is also widely agreed in Washington that it was El Salvador and not the United States that provided the crucial element: a few genuine democrats, people who are prepared to risk much for their goals and who have a solid base of popular support. President Jose Napoleon Duarte is first on that list, but it includes other officials of his party, many union and peasant leaders and a number of church, military and educational figures.

The United States supported them, pushed for changes and even issued orders, but ultimately the Salvadorans themselves have done the work of changing their instituions and fighting the war.

"You can't order people to make internal reforms," Langhorne A. Motley, assistant secretary of state for inter-American affairs who leaves office in July, said in an interview. "They've got to believe it has to be done for their own best interests."

As one White House official put it, U.S. aid has been vital but "it would have been useless without good raw material." He added: "If we'd only had raw material like that in Vietnam."

The Reagan administration saw El Salvador from the beginning as a test of whether it was possible to stop a Soviet-backed leftist insurgency without sending U.S. troops to "another Vietnam," for which there would be no popular support.

L. Craig Johnstone, deputy to Motley for Central America and previously an aide to then-Secretary of State Henry A. Kissinger during the Vietnam era, said he was tapped for the deputy's slot in 1981 after he warned the Central American bureau against the mistakes made in Vietnam, among them the error of taking over from the locals.

"The line that there was no military solution was in fact an administration maxim from the beginning" in El Salvador, Johnstone said. "We knew it had to be multifaceted," involving not only economic and social reform and a negotiating strategy but also "public diplomacy." Internal documents later called that "perception management."

Margaret Daly Hayes, now Washington office director of the Council of the Americas, which represents U.S. business in Latin America, handled Latin affairs for the Senate Foreign Relations Committee when it first discussed El Salvador in March 1981.

"Nobody knew anything. They the administration told us it was a manageable problem, a little aid now to replace what the army was losing and we'd deal with it," she said. "We drilled on saying 55 'trainers,' not 'advisers.' "

There was already resistance in Congress to aiding the Salvadoran government. The March 1980 assassination of Archbishop Oscar Romero and the December 1980 murders of four U.S. churchwomen shocked America and led to a temporary cutoff of aid.

Among the most deeply horrified was House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.). He has said that his close personal ties to members of the Maryknoll order have helped shape his critical views of U.S. involvement in the region, views that often stiffened House resistance to administration initiatives.

Administration officials also blame the church-related murders and the ensuing halfhearted probe by El Salvador's government for the rise of strong opposition from U.S. church groups, which Motley has called his thorniest problem.

"A lot of people's views, in and out of Congress, were permanently formed by those events," a White House official said. "We were 'on the side of the murderers' and that was it."

Partly because of Johnstone's advice to let the locals take the lead, the Reagan administration decided in June 1981 to give at least token backing to an extensive land reform program to which Duarte was committed, even though many conservatives regarded Duarte, a social democrat, as a dangerous leftist. The fact that liberals regarded him as a helpless pawn of the Salvadoran armed forces did not help his cause.

But Duarte's status improved in the White House when he rejected a joint communique from Mexico and France in August 1981 recognizing the rebel alliance as a legitimate political force.

"The Reagan people then believed Duarte was honest, a true democrat," recalled Ernesto Rivas Gallont, the former Salvadoran ambassador to the United States. "Then in November he promised elections no matter what, and that was very important."

Meanwhile, battles were erupting in Congress over the death-squad bloodbath in El Salvador and over persistent reports from the field that the Salvadoran army was drunk and inept. President Reagan asked for funds to train the Salvadoran army and instruct its chiefs on the value of taking prisoners. Critics saw the whole thing as a dangerous mess.

In December 1981, Congress approved a foreign aid authorization bill tying any further aid to a certification by the U.S. president every six months of El Salvador's progress in curbing human rights abuses, controlling the armed forces, investigating the murders, holding free elections and moving toward economic reform and negotiations with the guerrillas.

In a recent Washington appearance, Duarte said the conditions "played an important part in achieving the goal we're now attaining . . . . We had structural oppression for 50 years, and that's very hard to overcome."

Forcing probes of the murders, even superficial ones, was "a wrenching of an almost feudal system," Johnstone said. The conditions "helped at first" by convincing Salvador's leaders that Reagan could not act alone, Johnstone said.

Critics charged that the number of U.S. advisers was being juggled by temporary assignments, that a new air base and gunships were provided with no warning, that the certifications were a whitewash of major abuses and that the administration was giving lip service to peace efforts while pressing a military solution. The war seesawed, and the administration secretly authorized covert action against neighboring Nicaragua in order, it claimed, to cut off Nicaragua's arms supply to the Salvadoran guerrillas.

El Salvador's March 1982 elections were a world media event, but they settled nothing. Instead, they increased the power of the Salvadoran far right, and the Reagan administration was accused of covering up evidence of death squad involvement by Roberto D'Aubuisson, leader of the opposition party ARENA. Abuses continued, but Reagan certified progress four times.

In May 1983, the White House cashiered Thomas O. Enders, Motley's predecessor as Latin chief, for pushing a "two-track" policy in El Salvador of military pressure plus efforts for negotiations. Although there was much talk at the time about a conservative White House wresting policy control from a softer State Department, Johnstone said the two-track policy has been followed since.

"Some people believe the communists are inherently untrustworthy and will violate any treaty if they can find a way to do it, and they're right; another group focuses on do-ability, the need for public opinion support, and they're right, too," Johnstone said. "Enders tried to span the gap and used up his political capital, but anyone charged with implementing the policy has to do the same thing."

That is another way of saying that critics forced the administration to modify its position, said Rep. Michael D. Barnes (D-Md.), chairman of the House Foreign Affairs subcommittee on Western Hemisphere affairs. "We critics have clearly been vindicated," he said. "We were being called dupes of communism by some people in the administration . . . but Duarte's speeches now read like ours two or three years ago."

A pivotal moment, it is generally agreed, occurred in late 1983. Major U.S. military maneuvers had begun in Honduras, but the guerrillas were scoring repeated victories that raised the possibility that the Salvadoran army might lose.

Reagan's request for "emergency" aid to the Salvadoran government was bogged down in a hostile Congress, but the critics, who by then had come to know the guerrillas' political leaders personally, hesitated. "The Salvadoran left thought they had our liberals sewed up to kill military aid, so they were less interested in getting into negotiations," Hayes said. "That outraged a lot of people."

"Once we got involved with the Salvadoran government we couldn't just say to hell with them," recalled former representative Clarence D. Long (D-Md.), then chairman of the House Appropriations subcommittee on foreign operations. "The last thing I did was provide full military aid funding."

At about the same time, the National Bipartisan Commission on Central America, established by Reagan and chaired by Kissinger, had brought back an appalling vision of El Salvador.

"We had a very tense meeting with D'Aubuisson . . . . He in essence said he had every right to finger people as subversives and it wasn't his problem if they ended up dead a few days later, that they deserved it anyway and they were communists," said Barnes, who was present.

AFL-CIO President Lane Kirkland, a commission member, "said his people had been killed here in El Salvador and they weren't communists, and D'Aubuisson more or less said, 'That's your opinion,' " Barnes continued. "When then-U.N. Ambassador Jeane Kirkpatrick and the others brought that message back to Washington, it convinced some of the conservatives the right really was vicious."

In November, Reagan vetoed a renewal of the certification process in order, officials said, to make it clear to the Salvadoran armed forces that he didn't need Congress to push him on human rights. The U.S. Embassy began leaking names of death squad suspects, and Vice President Bush visited El Salvador in December to warn officials to clean up their act or face an aid cutoff.

"After that they believed us, but more importantly, the administration believed it, too," said a diplomat who had served in El Salvador.

The Kissinger commission reported in January 1984 that the guerrillas had legitimate grievances, although their Soviet backing threatened U.S. interests. It recommended massive economic and military aid, and in May Congress approved the first stage of such assistance when the House passed the bill by a four-vote margin.

The margin reflected the newness and the tentative nature of the convergence by Congress and the administration in a joint approach to El Salvador. It has persisted, with rough patches, since.

None of the officials interviewed said he thinks that the accord is guaranteed to survive, or that Duarte is guaranteed success in revitalizing his economy and achieving control of his armed forces. "The key is patience," Motley said.

Long remains among the most dubious. "If there's light at the end of the tunnel," he said, "it's a pretty long tunnel."