Five hooded men hopped out of a car at the checkpoint, heavily armed and clearly eager for blood. Iraqi policeman Maytham Talib figured it was time to quit his job.

"Each one of them had an automatic weapon. The police, we had four rifles, but only two worked. We had seven bullets for each rifle. We ran," said Talib, 25. He had already seen two colleagues gunned down at a checkpoint and two others slain by a grenade. He fled, took a bus home and has not been back to work since.

Established by the U.S. occupation authority and trained by foreign troops, Iraq's police and National Guard have been targets of insurgent attacks for months. With the formal end of U.S. occupation, they have been dying in ever larger numbers -- at least 127 have been killed in the last two months. The danger, coupled with low pay, has caused many to quit.

Defections pose a serious obstacle to the rebuilding of Iraq's security forces but not the only one. Planning has been chaotic, units have staged mutinies, and essential equipment has not been delivered. In recent months, the entire process of recruitment and training has been largely scrapped and begun again, and the interim Iraqi government that was installed on June 28 has dictated more changes.

"It was worse than starting from scratch," complained Sabah Kadhim, a top official in the Interior Ministry, which is in charge of police. "We had to weed out criminals from the policemen who the Americans put there."

After more than a year under the occupation, Kadhim said, "the police lacked efficiency, lacked organization, lacked cars, lacked weapons, lacked communication. Literally, they didn't have clothing."

Now, Iraqi and U.S. officials insist, the security forces are making progress. They say the police and National Guard are starting to conduct their own raids and perform well under attack. Training camps will soon crank out graduates. The heavy U.S. military presence is gradually shifting to a backup role behind Iraqi forces, they say, and there are plenty of new recruits waiting to take the places of those who quit. Last week, interim Prime Minister Ayad Allawi said the emerging security forces were starting to reduce the number of attacks in Iraq.

But his optimistic assessment seemed at odds with the daily drumbeat of mortar attacks, car bombs and ambushes.

"Security is the biggest problem we face," Defense Minister Hazim Shalan said in an interview. "We are working. But if you ask me, am I satisfied, I must say no."

Approximately 225,000 men and some women are listed as serving in the Iraqi security forces -- nearly 88 percent of the recruitment goal. But the numbers are debatable; the police carry 30,000 more names on their payroll than they can account for. Of those who exist, only a fraction have any training, often consisting of a few weeks at a boot camp. Top officials insist they have relatively few resignations -- no reliable figures are available -- but officers on the street say hundreds quit every month after getting their paychecks.

"I'm waiting to finish this month and get my salary, and then I will quit," said Heider Abbas, a policeman in Baghdad who cited low pay. A laborer or shop worker, he said, "gets more than we do."

U.S. planners say Iraqi security forces must be strong enough to fight the insurgency before American troops can withdraw. But the rush to build the forces -- an effort one officer called "30,000 in 30 days" -- led to a crisis in April when Iraqi troops refused to fight.

According to a Government Accountability Office report released last month, nearly 3,000 policemen quit or were removed in one week in mid-April. Among the Iraqi National Guard, desertions ranged from 30 percent in northeastern and central Iraq to 82 percent around the western city of Fallujah, where insurgents battled besieging U.S. Marines. In all, 12,000 soldiers did not show up for duty, according to the report.

"Given the poor performance of the Iraqi security forces during April 2004, it is unclear what level of security they will be able to provide during the period leading up to Iraq's national elections" scheduled for January, the GAO concluded.

Shalan, who became defense minister last month, said the forces had to be rebuilt from the ground up after the April failures. The occupation authority "failed in how they chose people to be employed," he said in an interview last week. "They depended on how a person looked. I think it was whoever the translators liked. That created many of the current problems."

Now, he says, his forces are getting organized. He pointed to a recent sweep through Baghdad's tough Haifa Street neighborhood that resulted in more than 150 arrests and to recent gun battles in which the National Guard stood its ground.

Though U.S. officials envisioned the National Guard as the country's principal domestic armed force, with the army serving as a defense only against external threats, Iraq's new officials have revamped that plan. Allawi announced soon after taking office that the army would be used for domestic security, and Shalan said he expected to transform at least part of the National Guard into the core of a new Iraqi army of six divisions with about 50,000 soldiers. With small air force and marine contingents, he said, Iraq's total armed services would be about 70,000.

Shalan said he is conducting background checks on the guardsmen, who he said number 40,000, and is recruiting more. He would not estimate how many of the current National Guardsmen he thinks will qualify for the army. Those who do not, he said, will become civil servants.

The interim Iraqi government has plans for a proliferation of security agencies in the Middle East tradition of multiple forces that watch each other. The list includes a general security directorate for intelligence, an intervention force, a coastal defense force, an air force, border, customs, immigration and security police, a SWAT team, a facilities protection service and a diplomatic protection service.

The government is also working to get rid of poor hires and nonexistent workers. Though the police force, for example, is paying about 120,000 people, only 87,000 are accounted for, according to British Brig. Andrew Mackay, the coalition adviser for the Iraqi police. "There's a degree of ghosts in there," he said.

Training has gone slowly. For the Iraqi army, only about 3,000 soldiers have been trained and deployed in the field, according to Brig. Gen. James Schwitters, commander of the coalition training team assisting the army. One source of delays has been the lack of adequate training sites for recruits, he said.

Only 6,000 police recruits have received training in a police academy, according to Mackay. Another 21,000 have undergone a three-week training course, he said. At least 60,000 are untrained. To help, Washington has issued a $500 million, two-year contract to train Iraqi police and soldiers in Jordan and has asked NATO for assistance with training.

Schwitters said the training programs would soon start to produce more soldiers. "We will have five battalions by the end of this month, and by the end of the year, 27 battalions," he said.

Mackay, too, is cautiously optimistic about the police.

"The Iraqi Police Service has some way to go before you can really consider them . . . effective," he acknowledged. "They have come a long way. We have given them equipment -- but we haven't given them enough. More needs to come. But they are around. They are visible. They are responding. They are conducting individual operations that they plan themselves, execute themselves, and do the follow-up themselves.

He and other officers cite examples of police stations that come under mortar attack one day and are fully manned the next, of wounded officers returning to work, of applicants still streaming into recruiting offices. "All of that is hugely encouraging," he said. But "there's a lot more that needs to be done."

At a National Guard recruiting office in Baghdad, young men jostle in line to apply. They say they are undeterred by the danger or the low pay.

"I was in the army before," said Hassan Ghrier, 22. "Yes, it's dangerous, but I don't care. And the pay is better than it was before, in the army. Anyway, it's a job."

Zain Ali Abdeen Basl, 22, has completed the first part of his training and is anxious to start working. He slips secretly onto the National Guard base from his home on Haifa Street, where many of his neighbors are insurgents or gangsters. "My neighbors threaten the security forces. But I just want to serve my country," he said.

They are bolstered by the guardsmen nearby. Ali Edan, 23, was shot once while on duty, but "I don't want to quit. I want to protect my country," he said. "I will show my children that I was hurt protecting Iraq. I am proud of that."

Another guardsman, who declined to give his name, described a different reality: "There are a lot of people who want to quit. Last month, we got 250,000 Iraqi dinars [about $170]. This month, we got only 210,000 dinars [$145]. Lots of guys are waiting until the end of the month to see what their pay is, and then they will quit. Our life is in danger out there, and no one takes care of us."

The commander of the base, Lt. Col. Heider Abdul Rasul, was in the Iraqi army's special forces for 20 years. He has about 950 soldiers and a list of 1,500 who are waiting to get in, he said.

Rasul insists he has had only 20 to 30 guardsmen quit since he took over seven months ago. But he added: "I've fired 300 soldiers who were too scared. If I have someone who's scared, I don't want him here."

Rasul is enthusiastic about the "excellent training" the Americans are providing, he said. His men typically get 20 days of training here and 13 days at a National Guard boot camp. But some of the techniques they are taught are frustrating, he said. In a recent gunfight with opponents hiding in high-rise apartment buildings, for example, "the coalition forces told us not to shoot where there are women or children. In the old regime, Saddam would have destroyed the whole neighborhood."

The American soldiers at the base have stepped back from giving orders; they now give advice, they say.

"The Iraqis want to stand up for themselves," said 1st Sgt. William W. Tager, who heads 13 U.S. advisers at the base. "I'm pretty surprised they haven't quit like they did before. They have picked up the ball more. They are a little more confident."

Still, he acknowledged, "it's slow. We know where we want to get them, but they aren't there yet."

Special correspondent Bassam Sebti contributed to this report.

Recruits line up to join an Iraqi security force. At least 127 security personnel were killed in the past two months.Former policeman Maytham Talib quit when gunmen, apparently set to attack, stopped at his checkpoint.Lt. Col. Heider Abdul Rasul said he had fired 300 National Guardsmen because they were "too scared."