The final vestiges of the Shah's authority collapsed as the Iranian army withdrew its support from the Prime Minister, and its troops from the streets.

Tehran, which for the past 48 hours has been a bloody battlefield, was given up to frenzied rejoicing of the supporters of the victorious religious leader, the Ayatollah Khomeini.

Earlier, the chief-of-staff of the armed forces, General Abbas Gharabaghi, met the man whom the Ayatollah has named as his Prime Minister, Medhi Bazargan, and said he would support a revolutionary Islamic republic. Little is known of the fate of Dr Bakhtiar although Radio Iran, already renaming itself the "Voice of Revolution," repeated rumours that he had committed suicide after resigning.

The Ayatollah told his supporters: "Victory is at hand." After 40 hours of vicious fighting, in which several hundred people died, the army's announcement that it would be neutral seemed to mean that it had abandoned its defence of the Government.

In most areas Khomeini supporters were firing their guns into the air to celebrate their triumph. The arms were captured from troops and police, or handed over by dissident servicemen.

At the city's military academy and the Bagh-e-Shah barracks, near Dr Bakhtiar's office, Khomeini's supporters were shooting in earnest to dislodge hard-core loyalist soldiers. Huge columns of smoke poured from both buildings.

At 6pm the newly captured state radio announced victory. It was a message heard by the whole world, including the Shah at his royal retreat in Morocco.

Voice of the Islamic Revolution, as the radio had been renamed, interspersed martial music with news of the day's battles, which had seen at least five army bases and countless police stations fall into the hands of the people. The Majiis, Iran's Lower House of Parliament, was taken over on the afternoon.

At 7.05pm the resignation of Dr Bakhtiar became official. The radio gave no details, but diplomatic sources believe he might have already left the country.

The death toll over the weekend was expected to exceed 300. Among the dead was a correspondent for the Los Angeles Times, Joe Alex Morris, who was struck by a stray bullet on Saturday.

Eleven thousand Iranian political prisoners, convicted murderers and burglars, and a handful of North Americans and Europeans hacked and clawed their way out of the country's largest prison.

Many jumped to freedom through windows whose bars had been physically bent and wrenched aside. Others rode to freedom on trucks and in cars abandoned by fleeing prison staff.

A commentator for the television station, set up in a converted school, urged people to keep their weapons, then hand them in to the headquarters today. Officials at the headquarters said the Tehran martial law administrator, General Mehdi Rahimi, had been captured and would be tried by an "Islamic court".

In the evening Tehran radio called on families to "stop using water immediately" as piped water supplies in certain areas had been "polluted". Hundreds of Khomeini followers blocked the streets around the Hotel Intercontinental, headquarters of most of the Western press, and refused to let anyone enter or leave.

The radio interrupted its regular programmes to announce that the Imperial Guard had moved out of Lavisan barracks, in the north of the city, towards the broadcast stations. The announcer appealed to the guerrillas and the Mojahedden, or Islamic fighters, to move against the troops.

However, a spokesman for the Imperial Guard denied plans to attack the insurgents. The radio broadcast another appeal - for Islamic fighters to stop wasting ammunition by wild firing in the air.

Earlier in the day the beleaguered armed forces signalled their surrender. The navy had already announced their decision to change sides and following a meeting of the army's high command Tehran radio said that all troops were being withdrawn to base. "We don't want any part in destroying the nation's unity," read the announcement. "Starting today we will play an apolitical role."

The crackle of heavy machine-gun fire resounded in the streets of Tehran all day, interrupted only by the screech of ambulances and the roar of captured army trucks and police wagons ferrying young men - their faces covered with balaclavas and clenching weapons - from battle scene to battle scene. Many rode pillion on motor-cycles, firing rifles crazily into the air. Following the takeover of arsenals nearly every male in the city is now armed to the teeth with sub-machine guns. AK 47s, M16s and even bazookas. Those without fire power were wielding clubs, kitchen knives, and even sickles.

In the vanguard were members of the country's two guerrilla groups, the Moslem-orientated Mojahedden and the Marxist Fedayeen who initially concentrated what few arms they had on specific targets. Among the first to fall was the Fawzieh army base in east Tehran. Later the revolutionaries looted the Israeli and Egyptian embassies and captured the Khasr prison and Golestan palace.

The British Embassy said Iranian troops at the gate had been disarmed by insurgents, however, who went away after being allowed into the chancery to make sure no weapons were concealed there.

Yesterday's battle started on Friday night with a television programme showing highlights of the Ayatollah's home-coming 10 days ago. Airmen at the Doshan Tappeh base in east Tehran switched off their sets and assembled in the barracks for a pro-Khomeini demonstration.

The Javidan Guard was brought in from the Lavizan base and, according to one airman, several technicians were rounded up, taken to the central parade ground, and shot.

One eyewitness said that the trouble was sparked when airmen went for their rifles and the shooting lasted until 3 a.m. on Saturday. Reinforcements were sent in from Lavizan the next morning with tanks, trucks, and armoured cars. Wary of further confrontation, several hundred airmen decided to leave, but as they walked unarmed towards the main gate the guard commander opened fire.

The men retreated, raided the arsenal and took to the roof tops. Outside, tens of thousands of people flooded into area to build barricades of sandbags, across the street. Soon the whole of south east Tehran, a working class district, was occupied.

In subsequent battles with the Javidan, at least 100 people were killed.

Hospitals also felt the wrath of the Javidan. Last night one hospital in east Tehran was attacked by helicopters and a Chieftain which, according to eyewitnesses, crashed straight through the hospital wall - and crushed several ambulances before leaving.

At the Sina emergency hospital, close to the central police headquarters, a doctor said yesterday that the 11 operating theatres had been working non-stop for 24 hours. Many were head injuries, he said, adding that the Javidan was making no effort to fire below the waist.