After being attacked twice last year by the Taliban, the radical Islamic movement that controls most of Afghanistan, Mazar-e Sharif could no longer claim to be that battered country's last refuge from civil war. But hardly anyone in the dusty city on the northern plains was prepared for what happened when Taliban militiamen took control with a vengeance on their third try.

On Aug. 8 and the days that followed, Taliban militiamen and their allies -- including militant Muslims from neighboring Pakistan -- methodically executed between 2,000 and 5,000 civilians in one of the deadliest mass killings of civilians in two decades of warfare in Afghanistan, according to interviews with witnesses who later fled to Pakistan and reports by international human rights investigators.

Taliban militiamen searched house to house for males of fighting age who belonged to the Hazara ethnic minority. Hazaras were gunned down in front of their families or had their throats slit in the same way Muslims slaughter goats for holiday feasts. Others, thrown into the city's overcrowded jail, were executed by firing squads or crammed into tractor-trailers, where they sweltered all day in the summer sun -- doors shut -- until most perished from suffocation or heat stroke. In the evenings, the heavy trucks hauled the bodies to the nearby desert and dumped them in heaps like trash, according to the reports.

Sketchy reports of the slaughter were circulated at the time, but the full extent and the systematic character of the mass murder there have only become known in the months since, as human rights investigators have interviewed survivors who fled to Pakistan and elsewhere.

The killings illustrate how the Afghan civil war -- which began in 1978 to overturn communist rule, raged during a 10-year Soviet occupation and eventually settled into factional fighting -- has in the past two years turned toward ethnic conflict fed by tribal hatreds and blood revenge. Although the Taliban fought its way to dominance under a unifying banner of Islam, in ethnic terms its rule represents a return to the pre-communist days of rule by Pashtuns, Afghanistan's largest ethnic group.

In taking over Mazar-e Sharif, the Taliban also added a sectarian twist. The Hazara group that was singled out for slaughter is predominantly Shiite Muslim; the Taliban is a Sunni Muslim movement. In addition, the Taliban's attack on Mazar-e Sharif claimed the lives of nine Iranians, provoking Shiite-dominated Iran to rattle a big Persian sword on the border, mobilizing tens of thousands of elite troops for military exercises that stretched over an entire month.

William Maley, an Australian specialist on Afghanistan, said that the Mazar-e Sharif killing was "striking in its viciousness" even by Afghan standards. "What we saw in August was not civilians caught in the cross-fire between combatants, but an orgy of killing driven by racial and religious prejudice," he said. "Afghanistan is teetering on the edge of major ethnic conflict and perhaps even a genocide."

Mazar-e Sharif had remained the last major city holding out against the Taliban's strict rule of Afghanistan, which has included the imposition of Islamic law and tight controls on women. But until the shooting started that Saturday morning in August, few residents had any warning that most of the forces defending Mazar-e Sharif had slipped away overnight or had defected, leaving the city's gates wide open to the Taliban. Shock troops arriving in pickup trucks and cars fired automatic weapons at everyone in sight, regardless of ethnicity, in an apparent effort to terrorize a rebellious population into submission, witnesses said.

"It didn't matter whether they were small children, women, men or old men. They were just shooting at people," said a Hazara woman now living in Quetta, a border city in Pakistan where thousands of other refugees from Mazar-e Sharif have made their way.

Down four broad avenues that radiate from Mazar-e Sharif's central square, antiaircraft guns mounted on parked military trucks sprayed heavy bullets as panicked merchants and shoppers broke into a desperate sprint for safety, according to a Hazara truck driver who watched from an upper floor of a nearby building. In the bedlam, speeding cars hit some people and raced over the bodies of others felled in the firing.

After a few hours, the shooting subsided. Blood stained the walls of shops and residential compounds. For at least three days, bodies lay where they fell on the orders of the Taliban commander who took charge of the city, witnesses said. It was not until the bodies began to rot and stink in the dry summer heat, threatening disease, that the commander, Manon Niazi, allowed burial of the dead. By then, stray dogs were feeding on the bodies.

Recent interviews of Hazara refugees -- who did not want to be named for fear of reprisals -- and reports released this month by the United Nations and Human Rights Watch were consistent in their general accounts of the initial indiscriminate killing, followed by days of targeting Hazaras. An Amnesty International report in September mentioned only the ethnic killings.

Officially, the Taliban regime based in Kabul says none of it happened, although Taliban officials have barred human rights investigators and journalists from Mazar-e Shaif.

The Taliban denounced the report of a U.N. human rights investigator as "vast propaganda," maintaining that its forces had killed only combatants, confiscated firearms from civilians and temporarily evacuated some residents.

But a former Pakistani intelligence official who visited the city afterward said that large-scale killing did occur -- after quick trials.

"Most of the group executions were carried out by the firing squads after summary Islamic courts found those people guilty of treason," the former intelligence official said. "The treatment meted out . . . was clearly defined in Islamic laws."

Refugees reported that the Taliban were accompanied by Pakistani fighters, identifiable by their language, dress and the flag of a Muslim fundamentalist Pakistani party aligned with the Taliban. Pakistan is one of three countries to recognize the Taliban as Afghanistan's legitimate government and has provided logistical support to its forces.

In responding to the U.N. report, the Taliban also cited the summary executions in May 1997 of an estimated 2,000 to 3,000 Taliban prisoners in the Mazar-e Sharif area. Human rights investigators have concluded that those killings motivated the militia to take revenge.

Hazaras, however, were not responsible for the killings. Although they started an uprising soon after the Taliban marched into the city in an earlier offensive in May 1997, a militia dominated by ethnic Uzbeks quickly took control of the situation and rounded up the Taliban prisoners.

Rather than avenging the 1997 killings, the Taliban instead appears to have massacred the Hazaras in August because of religious differences and an old blood feud.

Hazaras who survived the onslaught were pressured by Niazi, the Taliban commander, to adopt Sunni Muslim rituals, emigrate to Shiite-dominated Iran, pay a special tax as non-Muslims or face death, witnesses say.

In addition, the tribal code of the Pashtuns who make up the bulk of the Taliban binds men to avenge killings of their own. The Pashtuns and Hazaras have hated each other at least since the late 1800s, when a Pashtun ruler conducted a pogrom against Hazaras and confiscated their farmlands, handing them to fellow Pashtuns.

That 19th-century round of ethnic violence drove some Hazaras to Quetta; the small, struggling Hazara community here now serves as a refuge for new arrivals. The newcomers have crowded into run-down motels, dirt-floor basements and, in some cases, mosques. The financially strapped office of the U.N. High Commissioner for Refugees here has been able to provide limited aid to no more than 150 destitute families.

Despite their desperate circumstances, some refugees talked of revenge. A doctor who fled from south of Mazar-e Sharif, for instance, quoted a Hazara proverb about a defeated people rising to fight back. "When the glass is broken, it is getting sharper," he said. "We are the broken glass." Special correspondent Kamran Khan in Karachi contributed to this report.