An extensive shakeup in the commands of Argentina's armed forces has reaffirmed President Raul Alfonsin's political authority despite rising military discontent with his administration, political and military sources here said today.

The week-long military crisis appeared to end today with the swearing-in of Air Force Brigadier Teodoro Waldner as the head of the Joint Chiefs of Staff, the top military position under Alfonsin's 15-month-old democratic government.

Waldner, formerly Air Force chief of staff, replaced Army Gen. Julio Fernandez Torres, who retired along with Army Chief of Staff Gustavo Pianta, six other Army generals, four Navy admirals and two Air Force brigadiers. Gen. Hector Rios Erenu, considered a moderate supporter of government policies, was named Army commander and Brigadier Horacio Crespo became chief of the Air Force.

The command changes were the second ordered by Alfonsin in the last eight months and resulted in the most extensive purge of top officers since the president sent 40 generals and admirals into retirement after his inauguration.

The reorganization was ordered to quell mounting criticism of the government among top military ranks and an incipient challenge to Alfonsin's political authority by top generals of the Army, political sources said. The government also purged several Navy admirals who have led hard-line opposition to court cases against military officers for kidnapings, torture and murders during eight years of military government.

The changes came as the Radical party administration prepared for a crucial stage in its long-delayed prosecution of former military commanders on charges of repression during military rule from 1976 to 1983. Nine former service commanders-in-chief, including three former military presidents, are to go on trial next month in a civilian federal court despite strong opposition from much of the current military leadership.

Political and military observers here said Alfonsin had used the shakeup to reaffirm his government's authority and democratic priorities shortly before the trials and a high-profile visit next week to the United States.

"This measure will doubtlessly clean up the polluted political atmosphere . . . on the eve of an episode that will test the strength of the institutional order: the trials of the nine ex-commanders," observed military expert Horacio Verbitsky in the left-of-center weekly El Periodista.

According to accounts provided by government officials to reporters here, Alfonsin's decision to reorder the military commands was precipitated by a meeting of then Army chief of staff Pianta and Army generals 10 days ago attended by Defense Minister Raul Borras. Some generals strongly criticized Pianta for failing to press military criticism of the Radical administration, according to these accounts.

Fernandez Torres, who was named to the Joint Chiefs of Staff last July, had irritated the government in December with a statement spelling out the Army complaints.

Officials decided to respond by retiring Fernandez Torres and naming Pianta to the Joint Chiefs of Staff. The planned transition of commands, announced Monday, was plunged into crisis when Pianta, reportedly under pressure from the top Army commanders, refused to accept the new position.

The government retired Pianta and succeeded in imposing the command of Rios Erenu, whose ascension automatically forced the retirement under military regulations of six generals of greater seniority.

Rios Erenu and Waldner pledged at their swearing-in ceremonies to respect the constitution and military subordination to the civilian government. Several political observers here said, however, that Alfonsin, who has now retired 50 of the 53 generals serving when he took office, remains far from his goal of depoliticizing the military.