The government of Prime Minister Shahpour Bakhtiar -- and with it Iran's monarchy -- fell today after armed civilians took over most of Tehran and top military commanders swung their support behind the drive for a new Islamic republic.

The fast moving developments wiped out the last vestiges of the Iranian monarchy under Shah Mohammad Reza Pahlavi, who flew into apparent exile last month after 37 years on the throne.

Thousands of armed civilians, rebel airmen and deserters from other service branches -- most of them supporters of Islamic opposition leader Ayatollah Ruhollah Khomeini -- took over key military and government installations.

Overwhelmed by this show of force, Bakhtiar's administration, the parliament and the regency council representing the monarchy collapsed in a jumble of resignations.

Mehdi Bazargan is expected to take over as Iran's new prime minister Monday after an early morning meeting to complete formation of his Cabinet.

Bazargan, appointed prime minister of a provisional opposition government by Khomeini a week ago, went on television and appealed for restraint while warning the people to keep alert for possible reaction by military holdouts.

He said he had been assured by the military chief of staff, Gen. Abbas Gharabaghi, of the armed forces' support for his provisional government, which plans a transition to an Islamic republic to replace the 54-year-old Pahlavi rule.

Bazargan said he had been told by Gharabaghi that "the Army will not interfere in political affairs" and that it had "supported the will of the people" in ending its backing of the monarchy.

According to diplomatic sources, Bakhtiar handed in his resignation during a meeting with Bazargan this afternoon and then went underground.

The state radio and television, in the hands of rebels following the withdrawal of military units, broadcast what it described as rumors that Bakhtiar had committed suicide after mobs burned his house and ransacked his prime ministry office. The rumors could not be confirmed.

The rebels also captured several military bases, most of Tehran's 23 police stations and a number of government buildings including the parliament and the Golestan Palace, a former residence of the shah.

It was not immediately clear what was happening in the rest of Iran, but several cities already had been taken over by Khomeini's supporters in recent days.

Pitched battles went on into Sunday night for control of a few military garrisons still holding out around the capital. Many barracks, police stations and government buildings gave in to the rebels without a fight.

Anarchy and chaos reigned in Tehran's streets for most of Sunday. Thousands of gun-wielding men and youths -- armed during the takeover Saturday of a Tehran air base by rebel air force cadets and the sudden fall of numerous weapons depots and military installations -- celebrated their victory over the 20,000-member Imperial Guard, the military unit most loyal to the shah.

The American Embassy came under fire briefly, a spokesman there said, but no injuries were reported. The U.S. military mission headquarters in north Tehran was evacuated and later overrun by armed mobs, officials said. There were no immediate reports of any American casualties.

The embassy advised all Americans to stay home Sunday night and all day Monday and to keep in touch for possible evacuation plans. About 7,000 Americans -- down from a high of 45,000 last year -- remain in Iran.

A threat to storm the British Embassy was defused when troops guarding it turned their weapons over to a mob and left the premises. The Israeli trade mission was ransacked and the Egyptian Embassy was attacked.

Khomeini Sunday night issued an appeal for calm and asked supporters not to attack diplomatic missions or people. Nevertheless, his headquarters in southeastern Tehran, near the captured Doshen Tappeh Air Base was a staging area for rag-tag convoys of heavily armed volunteers being patched to besieged resisting military compounds.

One major target was the Jamshidiyeh Garrison in west Tehran, where a number of former ministers and high officials of previous governments under the shah are imprisoned. The volunteers said they were going there to capture former prime minister Amir Abbas Hoveyda and the former chief of the secret police, Gen. Nematollah Nassiri.

Ibrahim Yazdi, Khomeini's chief of staff, said Hoveyda, Nassiri and Tehran's military governor, Lt. Gen. Mehdi Rahimi, had been captured. Other reports said, however, that a military prison where Hoveyda and Nassiri were being held was still being defended by forces loyal to the shah.

According to a program outlined this week for transferring power to an "Islamic republic," Bazargan intends to organize a referendum on Iran's future government, followed by a constituent assembly to draft a new constitution and elections for a new parliament.

But Bazargan and Khomeini face the immediate task of defusing a dangerous situation in which thousands of people have taken up armed insurrection with mind-boggling speed. Many are youthful leftists or Islamic revolutionaries who seem to be in no mood to give up their weapons.

One of the first priorities of the Bazargan administration, diplomats said, will be to disarm civilian fighters. Diplomats said they could envision a situation in which those who refused to give up their guns would be branded as Communists and the army would be called in to disarm them.

"I am quite sure communist elements want to continue the disorders," said Lt. Gen. Mohammed Massumi, a senior War Ministry official.

He said the military was trying to persuade Khomeini to draw a distinction between his supporters and leftists, who he said should be immediately identified and disarmed.

Massumi was one of more than 20 senior officers who signed a declaration pledging to withdraw all units to barracks to avoid "dismembering the unity of the nation." The statement Sunday said the armed forces from now on would play "an impartial role" in Iranian politics.

Massumi said almost all the top commanders signed the declaration, including the heads of the Army, Navy, Air Force and Army aviation. But it was not clear whether it was also signed by the new chief of the Imperial Guards, the shah's elite the shah's monarchy appeared to head off the possibility of full-scale civil war for the time being, although observers said fighting could continue with hard-line imperial guardsmen who were still holding the shah's Niavaran Palace.

An eventual conflict between rival groups of the opposition also could not be ruled out, diplomats said.

At the Doshen Tappeh Air Base, at least six Imperial Guard tanks and as many as 50 Army trucks were seen burned out or abandoned today after a fierce battle Saturday night in which rebel airmen held the base.

The official Pars News Agency reported that more than 200 people were killed and nearly 800 wounded in the battle for the base as of 9 a.m. Sunday. The number of casualties in fighting for other installations later Sunday was not known.

Major battles flared at the Eshratabad army and police base in east Tehran, where the American military mission maintained a salvage department and motor pool. Civilian fighters, including leftists and Islamic guerrillas, eventually took the base and captured large stocks of arms after setting part of the compound on fire.

Weapons also were taken from a military installation in the Abbasabad fighting force that has been involved in most of the fighting with civilians and airmen in the last two days.

In any case, the decision to abandon District of Tehran, where civilians were seen walking out with automatic rifles and heavy machine guns.

Imperial Guards and Army aviation personnel were reported to be defending a base in south Tehran into the night Sunday as rebels poured fire into it from surrounding rooftops.

A two-hour battle raged at the lower house of parliament building not far from Khomeini's headquarters until "revolutionary forces" captured it. The victors danced on the chamber floor under ornate chandeliers and held up bottles of wine they had discovered in a storeroom.

As the revolutionaries gathered at Khomeini's headquarters for their assault on the Jamshidiyeh base, organizers with bullhorns supervised the loading of ammunition boxes into a convoy of captured military trucks and civilian cars. Some of the vehicles hauled mortars behind them, and a number of antitank guns were seen.

An estimated 5,000 to 10,000 armed men wearing street clothes and various kinds of military garb piled into the trucks and cars for the trip to the base.

Dozens of Army and Imperial Guard prisoners, including officers, were herded into Khomeini's headquarters. Tehran's military governor, Gen. Rahimi, was among those being held. Khomeini supporters said he would be tried by an Islamic court for "murders" while he held his post.