Renegade Iranian troops, defying their commander and condemning the country's new government, went on a rampage with tanks and machineguns today in the southern oil city of Ahwaz.

A cameraman for the American Broadcasting Co., who witnessed the incident, said 20 Iranians were killed and about 200 wounred before troops loyal to the new government put down the rebellion with gunfire and capured the renegade forces.

The mutiny in Ahwaz was the most dramatic of several signs of trouble today for the new prime minister, Shahpour Bakhtiar. They indicated Bakhtiar is proving unable to capitalize on the emotional release caused by the shah's departure yesterday to persuade Iranians to pull back from the year of turmoil that has transformed the country.

A similar but smaller-scale version of the Ahwaz incident was reported at Arak, about halfway between the oil fields and Tehran. Troops were said to have opened fire on demonstrators, killing five.

In Tehran, Justice Minister Yahyha Sadiq-Vaziri resigned, claiming he was powerless "in the present circumstances" to carry out Bakhtiar's key government promise -- prosecution of top Iranians arrested for embezzlement and misappropriation of funds.

That was taken as a reflection of unhappiness at a decision to allow the chief justice of the Appeals Court to preside over the capital case of his intimate friend, former prime minister Amir Abbas Hoveyda. Sadiq-Vaziri reportedly favored removing the chief justice from the bench or asking parliament to pass special legislation setting up a tribunal to try the top-ranking accused.

At Tehran University, leftist and religious demonstrators fought for two hours and witnesses reported a number of broken limbs and bloodied heads. Street demonstrations in the capital caused massive traffic jams. Police looked the other way and troops did not intervene.

Although most shops, other than food stores, remained closed, the central bank opened for business, including foreign exchange transactions which long had been paralyzed.

National Iranian Oil Co. sources reported that within the next few days Iran will be exporting about 2.1 million barrels of heavy fuel, which is clogging up storage capacity and limiting production for domestic use.

Under an agreement worked out with the striking oil workers, they lifted a hitherto total ban on oil exports to allow refineries to meet domestic wintertime requirements of 900,000 barrels a day.

On the political front, Bakhtiar's problems were confirmed when his erstwhile ally in the National Front, Karim Sanjabi, said the shah's departure was only "one of the preliminary demands of the Iranian people" and that the struggle will continue until the monarchy is overthrown.However, Sanjabi's principal lieutenant, Dariush Forouhar was in Paris negonegotiating with Ayatollah Ruhollah Khomeini, the shah's archenemy and theoretical National Front ally.

National Front spokesmen here said Forouhar hopes to persuade Khomeini to withdraw his renunciation of the Regency Council, the nine-man body the shah left behind to perpetuate the outward trappings of the monarchy.

Forouhar saw Khomeini last night and before seeing him again today reported Khomeini's "favorable" reaction to suggestions that the Regency Council and the ayatollah's own Islamic Revolutionary Council be allowed to coexist.

Although a partial solution to Western minds, its virtue would be to box in and control -- without actually destroying -- the Bakhtiar government that Khomeini and the National Front have declared illegal.

A controlled Bakhtiar Cabinet would function as an interim government and organize a referendum about the future formal government, allowing Iranians to choose whether they wanted to abolish the monarchy and establish Khomeini's republic or the Western-style republic favored by the National Front. On paper at least, such a compromise solution would help Bakhtiar, Khomeini and the National Front out of the present impasse.

As the Ahwaz incident showed, however, element's inside the army could still attack Khomeini if the Moslem divine returns to Iran in the near future as his many followers are demanding.

After a peaceful anti-shan demonstration by 20,000 marchers in Ahwaz yesterday, the 92nd Armored Battalion's commander told his officers and noncommissioned officers this morning that with the monarch's departure they were to obey Bakhtiar, the ABC cameraman said.

Three officers rebelled, yelled "traitor" and led some NCOs and troops with tanks and machine gun-mounted jeeps out of the command compound and into town, according to the cameraman.

He said he heard loyalist troops shoot at the rebels in in a futile attempt to stop them. Other witnesses said the column was brought under control by other troops only after a shootout.

The incident was serious enough for Bakhtiar to confirm that renegades were rounded up by loyalists. But he denied there were dead in an effort to play down yet another example of stresses in the armed forces.

Bakhtiar is badly in need of help to retain government authority. Even army hard-liners are reported to have second thoughts about their ability to maintain unity in the ranks if Khomeini returns, after the recent shows of fraternization between demonstrators and troops.

The new foreign minister, Ahmad Mir Fendereski, announced, meanwhile, that he has dismissed eight ambassadors -- to Britain, the United Nations, France, Brazil, India, Italy, Denmark and Syria -- and the national radio said the ambassador to the United States, Ardeshir Zahedi, had resigned.