Washington — The number of detainees the US military is holding in Iraq will probably exceed 15,000 by year's end – another factor America's next president must weigh when considering how much to downscale the US role in the country.

Last year, during the height of the "surge" of US troops, the United States held as many as 26,000 suspected insurgents. As security improved, commanders had hoped to whittle down the number of detainees, most of them Sunni, by reintegrating only the least dangerous individuals back into Iraqi society and leaving Iraq with a smaller group to manage. But the detainee population remains large, testing the resolve of Iraq's Shiite-led government to prepare to manage the detainees on its own by committing to fair treatment and due process.

The US is cajoling the Nouri al-Maliki government to step up efforts to build the legal and political capacity to resolve detainee cases once it assumes responsibility for them, presumably by next year. But progress has been slow with the negotiation-savvy Iraqis.

All of this is critical because the UN Security Council resolution governing Iraq and the US military's presence there expires at the end of December. By that time, the US must complete so-called status of forces agreements that allow the American force to remain in Iraq. Whether the Iraqi government is prepared to take custody of the detainee population is a key question, driving concerns over its large size.

The US holds detainees at Camp Cropper near Baghdad and Camp Bucca in southern Iraq. The facilities combined currently have about 18,900 detainees, a population that includes "very dangerous and determined people," according to a US military official in Iraq.

But the camps also hold thousands of moderates who don't necessarily adhere to an extreme ideology but were caught up in the insurgency, perhaps placing roadside bombs just for the money. Last year, the US worked to separate the extremists from the moderates, implemented new family visitation programs, and began giving each detainee a formal review, with the intent of releasing as many people as possible. American military officials want to ensure that their program of detainee "care and respect" will be continued once the Iraqis take over detainee supervision, as US forces draw down.

This year, for example, Task Force 134, the US command that oversees detainees in Iraq, has released about 13,000 people, even as new detainees have arrived. There is a net decrease, however, and senior defense officials hope to be holding only about 15,000 at year's end. But other US officials say the figure could be higher.

"Our goal is to teach, coach, and mentor our Iraqi partners in a way that will continue the mission of detaining those who pose an imperative threat, in a way that shows care and respect, ensures a policy of fair release, not mass release, and making the protection and security of the people of Iraq the primary concern," says Maj. Neal Fisher, a spokesman for Task Force 134 in Iraq, by e-mail. "These things should be the case regardless of the outcome of the current negotiations."

The detainee program under the US military had once been a disaster, exemplified by the Abu Ghraib prison scandal in 2004. It is now considered a model program and is credited with helping to improve security on the ground in the last year, as Sunnis saw the US military treating them fairly even while in custody.

Maj. Gen. Doug Stone, who led the American detention command until earlier this year, had pushed to have as many detainees released as possible, as part of the US counterinsurgency effort.

"One of the lessons of the detainee process that Major General Stone raised was how reintegration, close vetting, and education have a critical impact on stability and on how people perceive the impact of the security operation," says Anthony Cordesman, a senior fellow at the Center for Strategic and International Studies, a think tank in Washington.

But some field commanders' resistance to releasing thousands of detainees, as well as logistical challenges to reintegrating them back into Iraqi society, kept the detainee population high.

Iraq's notoriously weak criminal justice system is also a concern as the US weighs how ready Iraq is to take control of the detainee population. "It's not as if the system isn't getting any better, but it certainly isn't ready yet," Mr. Cordesman says.