A three-foot-high coil of razor wire, 21-ton armored vehicles and American soldiers with black M-4 assault rifles stood between tens of thousands of people and their homes last week.

At Checkpoint 301 on Tall Afar's eastern edge, cars packed with families and their belongings stretched back five miles. Hundreds of Iraqi men pushed toward a slim opening in the razor-wire fence, where two U.S. soldiers waited to frisk them before they reentered the city.

"Back off!" one of the soldiers shouted into the restless crowd. "Back! Off!"

The repopulation of Tall Afar, a city the size of Louisville, is only part of the U.S. military's task here after putting down an insurgency that had taken control of the local government. Like other U.S. units scattered across Iraq, the Americans here are trying to meet the needs of people desperate to see their city return to normal, while simultaneously battling armed insurgents who want to drive the U.S. troops from the country.

Fighting between U.S. forces and insurgents this month killed an estimated 180 guerrillas and no Americans in this city, according to U.S. military officials. Hakki M. Majdal, deputy director of Tall Afar General Hospital, said 55 Iraqis were killed and 157 injured; many were civilians, including seven women and seven children, Majdal said, holding a list of the casualties.

Far more numerous than the dead and wounded, however, were the people who fled the fighting in this hilly agricultural city of 250,000 people about 60 miles from the Syrian border. U.S. officers estimated that 150,000 residents were displaced, leaving Tall Afar a virtual ghost town when U.S. forces regained control of the city last Sunday. When Brig. Gen. Carter F. Ham, the commander of U.S. forces in northern Iraq, traveled into the city Thursday to meet the new local government, many shops remained closed. Scattered pedestrians walked the narrow streets in the blast-furnace heat as people trickled back into the city.

"I think Tall Afar will once again be a great city," Ham told the new mayor, Mohammed Rashid Hamid, as the two walked down the street, surrounded by armed U.S. troops and Iraqi police. "And I don't think it will take very long."

But the fighting has pushed reconstruction in Tall Afar back to square one. In a meeting Wednesday at the Army's Forward Operating Base Sykes, near Tall Afar, Maj. Tom O'Steen told Hamid: "I'd just like to start the meeting by asking the new mayor if we could confirm his name."

Ham said he had requested $3 million in emergency funding to rebuild Tall Afar's infrastructure. A team of civil affairs officers is working with Iraqi officials to restore basic services, including water and electricity, which U.S. forces had turned off for at least three days during the fighting.

A U.S. Army colonel handed out $200 bonuses -- the equivalent of about a month's salary -- to the 83 Tall Afar police officers who fought with the Americans; 517 others either deserted or joined the insurgents, U.S. military officers said. The Iraqis who switched sides included the police chief and his deputy, both of whom were detained by U.S. forces.

"We have to start from the beginning," the new police chief, Col. Ishmael Mohammed Shuaub, said Wednesday in a meeting with U.S. officers at their base near Tall Afar. "We must forget history now."

The insurgents' takeover here "wasn't something we expected," Ham acknowledged. U.S. intelligence officers and commanders said it grew out of an informal alliance of Sunni Muslim extremists connected to Abu Musab Zarqawi, a Jordanian believed to be linked to al Qaeda; Shiite Muslim followers of rebellious cleric Moqtada Sadr; holdovers from Saddam Hussein's ousted Baath Party; other disaffected Iraqis; and foreign fighters.

Commanders and soldiers from the U.S. Army's 5th Battalion, 20th Infantry Regiment, said they noticed a spike in attacks against U.S. forces in Tall Afar soon after Sadr and his followers left the southern city of Najaf in late August, following three weeks of intense fighting.

Lt. Col. Karl Reed, the battalion's commander, said that shortly after the Najaf agreement, fighters began to appear in Tall Afar wearing the black clothing associated with the Mahdi Army, Sadr's militia.

"This was the first time we really saw an organized insurgency inside the city," Reed said. "They began to outfit with all black and black masks and almost became more organized and militant. I don't know if it's related, but it seems like a couple days before that is when they all left Najaf."

Reed said he believed that "there is an element in the country that moves to whatever location best supports their operations. . . . I think it's being coordinated, for sure."

However, Majdal, the hospital official, said the insurgency grew primarily out of a combination of desperate economic conditions and mounting frustration with the American occupation. "There are no jobs, and if you are hungry, anyone can use you," said Majdal, a neurologist who sits on the committee that met with U.S. civil affairs officers to plan the reconstruction.

"The citizens are frustrated; everyone is frustrated," he said. "My house, for example, has been searched three times, and the last time they were very aggressive. They broke down my door. I was asleep in my house with my children, and suddenly [a soldier] was standing in front of me. I said, 'I am a doctor.' He said, '[Expletive] you.' "

Ham said the Americans' efforts have been complicated by the way Iraq's ethnic, tribal and religious groups are woven into Tall Afar's population. Though Iraq is predominantly an Arab country, the majority of Tall Afar's residents are ethnic Turkmen. And although northern Iraq is largely Sunni-populated, the city is mostly Shiite.

"I tell you frankly, having done this for nine months, that I didn't understand the complexity of this operation," Ham said.

"I didn't understand the complexity of the tribal nature of the Iraqi society and the extraordinary influence that tribal leaders play in all aspects of life here," he said.

Staff Sgt. Patrick Bloomer, who participated in the fighting, said he was frustrated that U.S. forces did not provide food, water or other assistance to people fleeing the city. "It seemed like the military part of the operation was sound, but if we're over here to help the people, we should at least try to do something," he said.

"For the last few days it's been bugging the crap out of me," Bloomer said. "You had pregnant women and children, and we have all this food and water stockpiled. We could have easily gotten it to them.

"I don't mind coming over here and doing my job, but it's not just conflict and combat. You've got to help people out just a little."

U.S. military officials said they are now trying to do just that. On Thursday, nine U.S. officers met across a table in the base mess hall with Hamid, the new mayor, and seven of his civilian aides to discuss the restoration of services in Tall Afar. But the meeting revealed more about the differences that the fighting has left.

Jabbing his left hand for emphasis as he spoke through an interpreter, Hamid told the Americans that the slow pace at which returning residents were being searched had paralyzed the city. He complained that women and children were being searched and said U.S. forces searching for remaining insurgents were relying on inaccurate information to detain people.

"About 40 percent of the information you have about the people of Tall Afar is wrong," he told the officers.

Maj. O'Steen responded that U.S. forces were frisking only military-age men reentering the city and were preparing to release about 40 detainees picked up the day before.

"We are caught in the middle between two fires," Hamid told the Americans. "On the one side, we have the terrorists, and on the other side, we have the coalition forces."

"As you know, this is a very important time for Tall Afar," responded Lt. Col. Kevin Hyneman, the deputy commanding officer for the 2nd Infantry Division's 3rd Brigade. "I don't want to rebuild it like an American would. I want to rebuild it based on your own priorities."

"But the most important thing is security," Hyneman said. "We don't want to have to go and do all of this again months from now or a year from now. I understand you are in a very difficult position here. You have the terrorists on one side and the coalition forces on the other. I hope by now you can trust the coalition forces. I know you cannot trust the terrorists."

Men are detained by U.S. troops searching for insurgents as they allow the return of residents to the city of Tall Afar.