A big Monday-morning quarterback question since ISIL began overrunning parts of Iraq as Iraqi military forces collapsed has been whether the United States should have kept in place a significant residual force, rather than withdrawing altogether after the U.S. combat mission there ended in late 2011. A significant part of this larger strategic question has been whether the United States could have secured agreement with the Iraqi government on a set of legal protections and immunities for U.S. troops, in light of political opposition in Iraq and then-Prime Minister Maliki's conclusion that any such agreement would have to be approved by Iraq's parliament.
In his forthcoming memoir, previewed in this Time article, then-Secretary of Defense Leon Panetta suggests that such a negotiated deal was possible, but for lack of White House leadership:
We had leverage. We could, for instance, have threatened to withdraw reconstruction aid to Iraq if al-Maliki would not support some sort of continued U.S. military presence. My fear, as I voiced to the President and others, was that if the country split apart or slid back into the violence that we’d seen in the years immediately following the U.S. invasion, it could become a new haven for terrorists to plot attacks against the U.S. Iraq’s stability was not only in Iraq’s interest but also in ours. I privately and publicly advocated for a residual force that could provide training and security for Iraq’s military.
Under Secretary of Defense Michèle Flournoy did her best to press that position, which reflected not just my views but also those of the military commanders in the region and the Joint Chiefs. But the President’s team at the White House pushed back, and the differences occasionally became heated. Flournoy argued our case, and those on our side viewed the White House as so eager to rid itself of Iraq that it was willing to withdraw rather than lock in arrangements that would preserve our influence and interests.
... To my frustration, the White House coordinated the negotiations but never really led them. Officials there seemed content to endorse an agreement if State and Defense could reach one, but without the President’s active advocacy, al-Maliki was allowed to slip away. The deal never materialized....
For a strongly contrasting position, see this account in Politico by then-Deputy Assistant Secretary of Defense Colin Kahl, now National Security Adviser to VP Biden:
As the senior Pentagon official responsible for Iraq policy during the first three years of the Obama administration, I had a front-row seat for the internal deliberations over how to end the war. Through the first half of 2011, there was a vigorous debate within the administration about whether U.S. forces should remain in Iraq beyond December, and if so, in what numbers and with what missions. Ultimately, at great political risk, President Obama approved negotiations with the Iraqi government to allow a force of around 5,000 American troops to stay in Iraq to provide counterterrorism support and air cover and to train the Iraqi army. But, as commander in chief, he was unwilling to strand U.S. forces in a hostile, anti-American environment without the legal protections and immunities required to ensure soldiers didn’t end up in Iraqi jails. These protections, which are common in nearly every country where U.S. forces operate, were guaranteed under the 2008 status of forces agreement negotiated by the Bush administration; Obama simply demanded that they continue under any follow-on accord.