East Timor's capital descended into chaos Saturday as rival gangs torched houses and attacked each other with machetes and spears, defying international peacekeepers patrolling in armed vehicles and combat helicopters. The prime minister said a coup attempt was underway.

The violence prompted thousands of residents to flee or hide, terrified, in their homes.

"What is in motion is an attempt to stage a coup d'etat," Prime Minister Mari Alkatiri told a news conference as fires raged across the city.

Minutes before he spoke, Australian troops disarmed up to 40 machete-wielding gang members half a block away.

The Australian troops, who answered an emergency call from the fledgling country's government two days ago, patrolled the city in armored personnel carriers and tanks, and Black Hawk helicopters thundered overhead.

Mobs rampaged regardless, and sporadic gunfire was heard throughout the city.

At least seven people were injured, mostly during street clashes. Despite threats to use force, foreign soldiers were not believed to have fired their guns.

Dozens of houses and cars were set ablaze in one early morning raid. Women and children fled screaming to seek shelter at a nearby church. Soon after, Australian soldiers rounded up dozens of civilians armed with machetes, spears and other weapons, questioning them and searching vehicles.

Thousands of other terrified residents loaded provisions onto trucks and cars and drove to embassies, the airport or makeshift shelters.

Several ambulances were seen racing through the streets, sirens blaring.

"The Timorese are fighting, so we are afraid. At night they fire guns, or maybe worse, so I had to run to the United Nations," said Anim, a mother of four, as she prepared for a night in an overcrowded refugee camp at the U.N. headquarters.

"The west and the east, they want to fight. They are enemies from long ago. Now they are trying to provoke each other."

The violence was triggered by the March firing of 600 disgruntled soldiers — nearly half the 1,400-member army — and is the most serious crisis East Timor has faced since it broke from Indonesian rule in 1999.

After staging deadly riots last month, the sacked troops fled the seaside capital, setting up positions in the surrounding hills, and threatened guerrilla war if they were not reinstated.

They started ambushing soldiers in the capital Tuesday, sparking days of pitched gunbattles with the military that so far have killed 23 people and injured scores.

Deep social divisions dating from East Timor's 24-year occupation by Indonesia have surfaced. Many in the west were perceived to sympathize with the colonial masters in Jakarta, while the east favored independence.

The dismissed soldiers are largely from the country's west, while the military leadership originates from the east. Many of the renegade soldiers claim they were denied promotions and coveted assignments because of discrimination in the armed forces.

All the bad blood now is spilling onto the streets, where angry and impoverished civilians — nearly half the population of around 1 million is unemployed — also are attacking each other.

On Saturday morning, young men armed with slingshots and rocks targeted what they believed were the homes of soldiers who sympathized with Indonesian army militias responsible for deadly violence that accompanied Indonesia's withdrawal.

A mob torched the house of a government minister, killing five children and an adult whose charred bodies were found Friday. Ten unarmed police also were gunned down by soldiers as they left their headquarters in downtown Dili under U.N. escort Thursday.

The more than 1,000 Australian troops arrived after East Timor's government said it could not control the situation. New Zealand, Malaysia and Portugal also agreed to help, and some advance forces already were on the ground.

"There is no solution," the Rev. Jose Antonio said at a church where hundreds of people sought shelter. Hatred between the warring factions runs long and deep, he said, "and this is an opportunity for revenge."

Foreign Minister Jose Ramos Horta said Friday he believed the issues that triggered the violence were "still capable of resolution."

The impoverished nation received millions of dollars in international aid over the last seven years, much of it focused on building up the military.