The last 24,000 U.S. troops are scheduled to leave Iraq in the next few weeks so that most can be home before Christmas.

The departure is required by the 2008 Iraq-U.S. Status of Forces Agreement signed by Iraq Prime Minister Nouri al-Maliki and then-President George W. Bush and approved by the Iraqi parliament, giving it the status of law.

Meanwhile, don’t believe those agonized voices on Capitol Hill complaining that “having won the war” President Obama is “about to lose the peace” because he didn’t negotiate well enough with Maliki to allow 10,000 to 15,000 U.S. troops to remain.

There will be a U.S. military presence. The Office of Security Cooperation (OSC), operating under the U.S. Embassy in Baghdad, will have several hundred military personnel, and at least an equal number or more U.S. contractors, who will work with Iraqi security forces. Ongoing negotiations with Iraq about OSC activities will determine exact staffing numbers.

Normally, such an office would focus on training for the $8 billion in equipment that Iraq has purchased from U.S. companies. Under current plans, the OSC will do much more.

Gen. Martin E. Dempsey, chairman of the Joint Chiefs of Staff, described the other roles Tuesday at a Senate Armed Services Committee hearing. He called the OSC in Iraq “a relatively small training and advisory contingent” that “will advise the ISF [Iraq Security Forces] in closing their capability gaps, assist in the expansion of their training programs, and facilitate their procurement of new equipment.”

Once the OSC agreement is completed, Dempsey said, other negotiations will determine “what exactly are additional areas where we can be of assistance, what level of trainers do they need, what can we do with regards to CT [counterterrorism] operations, what will we do on exercises, joint exercises.”

Working out of the embassy and 10 military bases, “We will be embedded with them as trainers not only tactically, but also at the institutional level,” Dempsey said.

Iraq has purchased 140 M1 Abrams tanks, and OSC personnel will stay at the base in Besmaya, east of Baghdad, where there is a tank gunnery range. Iraq will be responsible for the base’s outer perimeter security, Dempsey said, adding, “We’ll have contracted security on the inner perimeter,” where the OSC people will live.

OSC people will partner with 4,500 Iraqi special forces troops, with some working out of their counterterrorism headquarters. Dempsey said current discussions focus on OSC personnel continuing to train these units where they “would stay inside the wire [the base outer perimeter] of places where this counterterror force is located, not go with them on missions . . . [but] continue to train them to go on missions.”

Dempsey said the Iraqi security forces “are extraordinarily good . . . at closing onto a particular [terrorist] target when the target is identified for them . . . generally through human intelligence.” He said they lack “the ability to fuse [signal and human] intelligence . . . and identify a network” and the OSC will have “a cadre of trainers to continue to build that capability and close the gap.”

Defense Secretary Leon E. Panetta, referring to his previous tenure as CIA director, said, “We were helping to provide a lot of intelligence and assistance.” Without providing any details on who or how, he added, “I think some of those efforts will continue to provide intelligence” to the Iraqis.

Another major concern tied to the withdrawal was the role U.S. troops played in northern Iraq, keeping peace between the Kurds’ pesh merga forces and Iraqi government soldiers. U.S. soldiers have been withdrawn from checkpoints but some U.S. officers continued to work at a Combined Coordination Center in Ninewa. OSC personnel will continue to staff that Kurdish-Iraqi facility. “Our presence in the coordination center provides a stabilizing influence to get them to find negotiated answers, not violent answers,” Dempsey told the committee.

Sending U.S. troops back is still a possibility. Maliki is coming to Washington next month and the issue could come up. In January, Gen. James Mattis, head of Central Command, goes to Baghdad for a meeting of the High Coordinating Council set up under the 2008 Strategic Framework Agreement. That forum is “to discuss future security cooperation” and is a place to negotiate any new troop arrangements, Dempsey said.

Now, back to those complaints Tuesday from Sens. Lindsey O. Graham (R-S.C.), John McCain (R-Ariz.) and Joseph I. Lieberman (I-Conn.) that administration negotiations had failed to keep some American units in Iraq.

Graham implied there was no agreement because leaving thousands of U.S. troops in Iraq after Dec. 31 would hurt President Obama’s reelection chances. He disregarded Panetta’s and Dempsey’s insistence that negotiations broke down primarily because the Iraqis — based on their own domestic political situation — insisted that any remaining U.S. forces would not continue to have immunity from prosecution under Iraq criminal law.

Brett McGurk, a senior Iraq White House adviser under both Bush and Obama, supported the two officials. He testified immediately after Panetta and Dempsey.

“Iraqi and U.S. legal experts had determined legal immunities for U.S. troops could only be granted by the Iraqi parliament [and] the parliament would not do so,” he said.

Iraqi political leaders on Oct. 4 confirmed that parliament would not vote for U.S. troop immunity and that polls showed 90 percent of Iraqis in Baghdad and 80 percent across the country wanted U.S. troops out of the country, McGurk added.

Had the polls indicated a favorable response on the immunity issue “the numbers would surely be higher,” McGurk said.

While listening to the hearing, I recalled a lesson from the late senator J.W. Fulbright, chairman of the Senate Foreign Relations Committee, for whom I twice worked in the 1960s on 18-month sabbaticals from journalism.

“If you don’t understand the domestic problems of leaders of a country you are dealing with,” Fulbright would say, “you cannot have a realistic foreign policy with them because every country’s foreign policy is driven by its domestic situation.”