Army generals and civilian politicians backed by the United States appear to be gaining the upper hand in what has become a bitter power struggle against Roberto D'Aubuisson, the right-wing extremist whose conservative forces gained substantial control over the Salvadoran government in U.S.-sponsored elections last March.

The internal political battle has become so intense that, in the opinion of some diplomats and officials here, it has temporarily overshadowed American and Salvadoran military efforts to wage the three-year-old civil war against Marxist-led insurgents that the Reagan administration has said must be won.

The United States, according to officials here and in Washington, believes that D'Aubuisson's extremism makes him an unreliable ally, and that his unswerving opposition to economic reforms and alleged association with right-wing death squads may undermine already tenuous congressional approval for U.S. aid to El Salvador.

His principal opponents are Defense Minister Gen. Jose Guillermo Garcia and provisional President Alvaro Magana. U.S. Embassy support for them -- including control of $200 million in economic aid and $81 million in military support this year -- has been crucial in turning the internal power balance against D'Aubuisson.

In recent weeks, the conservative coalition that backed D'Aubuisson's bid for power in March has divided and is disintegrating.

Garcia has been able not only to block behind-the-scene maneuvers to oust him, but also has succeeded in dislodging Col. Nicolas Carranza, one of D'Aubuisson's key allies among the military's senior commanders, from the sensitive intelligence-gathering job of heading the nation's communications network. Moreover, D'Aubuisson's allies in the Cabinet are under mounting attack and some of his closest friends are under open, vehement attack as murderers by U.S. officials.

The increasingly open interventions of U.S. Ambassador Deane R. Hinton, who recently said in a public speech that the abuses committed by the extreme right must be curbed, are seen here as strengthening the hand of Magana and Garcia. The defense minister, although still considered a hard-liner on the question of human rights and some reforms pushed by the United States, now argues that American aid is decisive in the effort to defeat the Cuban- and Nicaraguan-backed guerrillas.

D'Aubuisson apparently believes that El Salvador can survive without American help, and has reacted sharply to what his supporters characterize as unwarranted meddling by Hinton intended to overturn the results of the March elections, which Washington pronounced free, fair and decisive for the future of democracy in Central America.

A defiant D'Aubuisson reportedly told a group of his dwindling supporters last week that his opponents "believe that with the support of the gringos and all the international aid they can defeat us."

During a recent interview, Hinton put the situation in its starkest terms as the embassy and its political allies view it.

"I don't really think they'd have much chance of success without our assistance," said Hinton. He argued, as Washington has done here since 1979, that U.S. aid has had a restraining influence and that without it the extreme right would gain complete control of the government and try to solve the guerrilla problem through self-defeating slaughter eventually leading to a leftist victory.

"So in the end," Hinton said, "we would end up with more bloodshed and a totalitarian government here that would make the Sandinistas look like a bunch of Boy Scouts."

The guerrillas reject the ideological judgments in this scenario, but they certainly share the conclusion that they would win if Washington were not underwriting the current government.

D'Aubuisson himself has seemed to waver on this question from time to time, attempting for instance to sabotage the U.S.-backed agrarian reform program, then claiming amid threats of a U.S. aid cutoff that he never had any such intention.

After the March elections, where D'Aubuisson's Arena Party won 19 seats in the 60-seat constituent assembly, he joined the National Conciliation Party, El Salvador's traditional ruling group that won 14 seats, plus the centrist Democratic Action with two seats and a right-wing party with one seat for a solid 36-vote majority that immediately elected him assembly president.

The opposition, composed of the Christian Democrats with 24 seats, didn't have a chance. In September, however, D'Aubuisson's arithmetic started to go wrong when the National Conciliation Party split, and took five of its members, plus the party name and its two Democratic Action allies, across to the other side.

Not only was the right-wing coalition destroyed, leaving it in the minority with only 29 seats, the remaining nine National Conciliation votes formed a new rightist party under the leadership of ex-colonel Roberto Escobar Garcia that is drawing much of D'Aubuisson's old, moneyed backing. Some of Escobar Garcia's strongest support comes from the same wealthy farmers whose losses under the agrarian reform D'Aubuisson has been unable to reverse.

Some of D'Aubuisson's greatest recent setbacks came as he and the people he has represented tried to reassert their power.

After Magana, the middle-of-the-road military's handpicked president, tried to pull together a government of national unity in August with a pact signed by all parties, the extreme right began serious behind-the-scene maneuvers at several military garrisons to win support for the ouster of Garcia from the Defense Ministry.

"The effort didn't prosper," as one commander put it. "I think right now the officers are more interested in looking at how to manage the military situation than dealing with things like that." Garcia and Magana retaliated with the ouster of Carranza.

D'Aubuisson tried to have the Magana-appointed head of the Central Bank investigated, apparently with a mind to installing one of his own people.

That effort did not prosper either. Now the public health minister appointed by D'Aubuisson's party has been forced to resign, according to senior government officials, and the key agricultural agencies he won control of in April are under increasing pressure from below by Christian Democrat-allied labor unions.

But the most striking setback for the extreme right came when D'Aubuisson tried to ram a measure through the assembly last month that would have "rejected absolutely all attempts at dialogue or negotiations with the terrorist minorities," meaning the guerrillas and their political allies.

The action followed a guerrilla proposal for a form of "dialogue" with the government, instead of its previous call for substantive "negotiations." Magana and others showed interest.

No one doubts that seven months ago, during what one Salvadoran priest called the "exaltation of ultra-conservatism" after the election, such a measure, prohibiting any form of contact with the guerrillas, would have passed overwhelmingly.

D'Aubuisson is still holding his own on some fronts. Next to the overall political struggle, the most vexing problem for Washington and Garcia at the moment has been their failure to bring to prosecution a D'Aubuisson ally, Lt. Rodolfo Lopez Sibrian, for the murders early last year of the head of the agrarian reform program and two American advisers. Having twice been released by judges whom officials have characterized as afraid of or allied with D'Aubuisson, Lopez Sibrian has now been sent to the war front by Garcia, who currently is looking for a new legal avenue against him.

But recent victories against D'Aubuisson have raised hopes on the moderate left and even the moderate right that the time is drawing near when the combatants in this country's bloody civil war will at least begin talking about talks to end it.

They note that both the left and the right are looking at carefully limited procedural steps that could lead to contacts that both sides would find acceptable.

"Remember the Vietnam war? How long they were discussing the shape of the table?" Ruben Zamora of the guerrilla-allied Revolutionary Democratic Front asked in a recent interview in another Central American capital. "To some extent this is a similar thing."

But nobody on the left or the right is admitting to substantive changes in their posture toward talks.

Successive governments have said for two years they would talk to the guerrillas about bringing them into the electoral process but they would not negotiate the composition of the government. That has also been, and remains, the U.S. position.

The guerrillas have said since the summer of 1981 that they want negotiations without prior conditions but that they want everything to be open to discussion.

In addition to hard-liners on both sides intent on scuttling such initiatives, violently if necessary, there are many members of the "pro-American" group who say privately that they are drifting along with the slow tide toward talks only as a political tactic or for propaganda purposes. This is particularly true in the Army.

There are fears at the embassy and among the people it backs that D'Aubuisson or his followers will bolt the system completely, as they have done before, and will resort to the use of "death squads" to deal with the people they consider enemies.