A week before the last U.S. soldiers left his country in December 2011, Iraqi Prime Minister Nouri al-Maliki traveled to Washington to meet the team that would help shape Iraq's future once the troops and tanks were gone.

Over dinner at the Blair House, guest quarters for elite White House visitors since the 1940s, the dour Iraqi sipped tea while Secretary of State Hillary Rodham Clinton spoke of how her department's civilian experts could help Iraqis avoid a return to terrorism and sectarian bloodshed.

Iraq would see a "robust civilian presence," Clinton told reporters afterward, summing up the Obama administration's pledges to Maliki. "We are working to achieve that," she said.

Less than three years later, the relatively calm Iraq that Maliki had led in 2011 was gone. The country's government was in crisis, its U.S.-trained army humiliated, and a third of its territory overrun by fighters from the Islamic State. Meanwhile, State Department programs aimed at helping Iraqis prevent such an outcome had been slashed or curtailed, and some had never materialized at all.

Clinton's political foes would later seek to blame her, together with President Obama, for the Islamic State's stunning takeover of western Iraq, saying the State Department failed to preserve fragile security gains achieved at great cost by U.S. troops. Republican presidential nominee Donald Trump last week asserted that Obama "founded" the Islamic State and that Clinton was "the most valuable player" in the group's creation. Trump later contended that he was being sarcastic.

But an intensive review of the record during Clinton's tenure presents a broader picture of missteps and miscalculations by multiple actors — including her State Department as well as the Maliki government, the White House and Congress — that left Iraqi security forces weakened and vulnerable to the Islamic State's 2014 surge.

Documents and interviews point to ambitious plans by State Department officials to take control of dozens of military-run programs in Iraq, from training assistance for Iraqi police to new intelligence-collection outposts in Mosul and other key Iraqi cities. But the State Department scrapped or truncated many of the plans, sometimes at the behest of a skeptical Congress and other times on orders from the White House, which balked at the high costs and potential risks of U.S. civilians being killed or kidnapped. Still other efforts were thwarted by a Maliki government that viewed many of the programs as an unwelcome intrusion in Iraqi affairs.

Senior State Department leaders were at fault as well, according to documents and interviews with officials who helped manage Iraqi aid programs after the withdrawal. By early 2012, pressed by the White House to reduce the U.S. civilian footprint in Iraq, the department had begun implementing sweeping, across-the-board cuts that extended to security and counterterrorism initiatives once considered crucial for Iraq's stability after the withdrawal of U.S. troops, a joint investigation by ProPublica and The Washington Post found.

Clinton, a member of the administration's national security team at the time, argued at first in favor of many programs that the State Department eventually cut, according to current and former U.S. officials familiar with internal White House deliberations. For the Democratic presidential nominee, U.S. policy misadventures in Iraq, from the initial invasion and occupation to the disasters after the U.S. troop withdrawal, have persistently undermined Clinton's efforts to tout her extensive record in foreign policy. Candidate Clinton has frequently pushed for more assertive engagement with Iraq's military and tribal alliances to help repel the Islamic State, essentially arguing for an expansion of programs that were curtailed on her watch after the U.S. troop withdrawal in 2011.

A State Department team that administered the cuts under White House direction eventually ended up with a $1.6 billion surplus — money initially appropriated for Iraq that was freed for use in other conflict zones, including Libya, officials and documents say.

The downscaling was done over the objections of U.S. military leaders on the ground, who said the slashing of key assistance programs — in a few cases, by more than 90 percent — left the U.S. government increasingly in the dark about developments outside the Iraqi capital. Some former officers who managed Iraqi aid programs say the cuts were a factor in the slow deterioration of Iraq's security forces in the months before the Islamic State's 2014 assault.

"Our job was to prevent this from happening," said retired Rear Adm. Edward Winters, a former Navy SEAL and deputy director of the Office of Security Cooperation in Iraq, a Pentagon organization overseen by the State Department that managed the bilateral security relationship.

"We felt the capability to do that was being taken away."

'A Strategic Vacuum'

Current and former Obama administration officials, including some who sparred with the State Department over Iraq policy, defend Clinton as one of the most vocal advocates for a muscular U.S. presence in Iraq after the withdrawal deadline. Clinton argued publicly and privately for keeping a contingent of U.S. troops in Iraq after Dec. 31, 2011, and when that effort failed, she lobbied the White House and Congress for money to fund civilian-run security programs in Iraq, her former aides said. In written memos and in meetings as part of the president's national security team, she questioned Maliki's ability to keep the country united and warned that instability could lead to a resurgence of al-Qaida in Iraq, or AQI, the terrorist group that later renamed itself the Islamic State, the officials said.

"She was seized with this," recalled Deputy Secretary of State Antony J. Blinken, who was national security adviser to Vice President Biden and then deputy national security adviser to President Obama during key discussions about Iraq policy. "She recognized that AQI was down but not out, and pressed the Iraqis, and us, to keep taking the fight to them."

But, in scaling back civilian assistance to Iraq, Clinton's aides cut aggressively and sometimes unwisely, internal auditors later concluded. The reductions met cost-cutting goals but did not "fully consider U.S. foreign policy priorities in Iraq," an internal review by the State Department's inspector general said. Some of the cuts were not fully implemented until after Clinton's departure in early 2013, though the plans were largely in place, former aides said. The report is silent on Clinton's role in the reductions, or views about them.

"There was a period of time after the transition from the military-led mission to a civilian-led mission when strategic decisions were not made, with one official calling the period 'a strategic vacuum,'" the inspector general's office said in its 2013 report, citing interviews with department officials in Washington and Iraq. It said the cuts were driven by "Congressional and White House concerns that the Department quickly reduce costs and security vulnerabilities and address [the Iraqi government's] desire for a more normalized U.S. diplomatic presence."

Among the casualties was a U.S. Army-run Iraqi tribal reconciliation program with a record of successfully resolving disputes between Iraq's querulous Sunni, Shiite and Kurdish factions. Animosity between Sunni tribes and Maliki's Shiite-led government would become a key factor in the Islamic State's takeover of Iraq's Sunni heartland in 2014.

Asked to account for such cuts, a State Department spokesman said in an email that diplomats lacked "the personnel or financial resources" to continue many of the programs begun by the Pentagon during an era when tens of thousands of U.S. troops were serving in Iraq. In any event, the result was "lost trust with the Sunni community" and the abandoning of an important window into what was really happening inside Iraq, said retired Army Col. Rick Welch, who oversaw the program before the military withdrawal,

"No one from the State Department ever contacted me," Welch said in an interview. Eventually the Baghdad-based reconciliation effort was scaled back "to a trickle," he said, "and then nothing else happened."

'It Was the President's Directive'

In the first weeks of his presidency, President Obama flew to Camp Lejeune, the sprawling Marine base in North Carolina, to repeat a promise made throughout his election campaign: a pledge to wind down America's wars in the Middle East. He told the troops that "the war in Iraq will end" through a responsible drawdown of U.S. forces in Iraq by Dec. 31, 2011, the deadline set three years earlier by the George W. Bush administration.

In reality, few within Obama's own administration expected that the entire U.S. contingent would exit Iraq by that date, current and former aides say. In interviews, State Department and Pentagon officials said they were convinced that Iraq would ultimately negotiate an agreement to leave a modest contingent of U.S. soldiers — perhaps 10,000 or so — in the country to ensure stability and serve as a bulwark against a resurgence of al-Qaida in Iraq.

The presence of even a small American force would have provided a substantial benefit for U.S. diplomats in Iraq after 2011, assuring that the Pentagon would continue to take the lead in U.S.-Iraqi military liaison programs while also helping with mundane but necessary functions such as security, medical care, food service and transportation on the ground and in the air.

But with a deadline looming and no firm decision from the White House, the State Department began to develop plans for hiring thousands of contractors to perform the same services at higher costs. The uncertainty lingered until October 2011, when the talks collapsed just 10 weeks before the deadline for pulling all U.S. forces out of the country.

Throughout this period, Clinton continued to campaign for what several aides called a "robust" mission for American diplomats in Iraq, preferably backed by a significant U.S. troop garrison. Her advocacy was recalled by numerous military and intelligence officials who participated in classified discussions on Iraq. It was also expressed publicly in news conferences and congressional testimony at the time.

"She was very focused on how to apply the full weight of the U.S. government to locking down that residual troop presence," said Jake Sullivan, the State Department's director of policy and planning who later became the top foreign policy adviser to the Clinton campaign. As prospects for U.S. troop garrisons began to dim, Clinton "insisted on a robust contingency planning process, to leave nothing to chance on how we protected our civilian presence and how we made sure that we were supporting the outlying posts beyond Baghdad," Sullivan said.

State Department officials initially planned for taking control of more than a third of the 1,300 programs and missions run by the Pentagon in Iraq. That alone, as Clinton herself would acknowledge, constituted the "largest transition from military to civilian leadership since the Marshall Plan," the extensive U.S. aid effort after World War II.

Contingency plans created in 2010 envisioned taking over key security missions, such as the tribal reconciliation program. Another initiative called for building new diplomatic and intelligence outposts around the country to give the United States a presence in cities that once hosted American military bases. These facilities, called "Enduring Presence Posts," or EPPs, were initially planned for five Iraqi locales: Irbil, Diyala province, Kirkuk, Basra and Mosul.

State Department officials urged Congress to approve funding for the EPPs, saying the listening posts would help "mitigate ethno-sectarian conflict" while allowing the security officials to better "forecast, prevent or contain instability outside of Baghdad."

"Spotting emerging problems early is going to be critical," Clinton's aides wrote in a 2010 staff report to lawmakers. The report raised concerns about the department's ability to carry out some of its new mandates without U.S. military support, but it urged congressional appropriators to put up the necessary financial backing.

In Washington, both the White House and Congress viewed the plans with deepening skepticism. At a March 2011 Senate Appropriations Committee hearing, Sen. Lindsey O. Graham (R-S.C.) appeared to scoff at the idea of a civilian force of diplomats and contractors "trying to do business in Iraq all over the place with no troops.

"That is basically a private army replacing the American military," Graham said to Clinton. "So I'd like us to think long and hard as a nation — does that make sense?"

The cost of building, equipping and securing diplomatic enclaves in Iraqi cities such as Mosul — a hotbed of Sunni terrorism in 2011 — struck senior Obama aides in the meetings as exorbitantly expensive and impractical, even more so because of Maliki's growing antipathy toward U.S. interference in Iraq's domestic affairs, according to current and former aides who participated in the private discussions.

The loss of a U.S. troop presence meant the closing of all U.S. military installations, including dozens of Provincial Reconstruction Teams, the smaller regional units from which U.S. military and civilian workers administered aid to local towns and tribes. Unable to rely on Iraqi help, State Department officials would have to hire an army of contractors to replicate the functions and services previously provided by the Pentagon. For U.S. diplomats, a routine journey along the 40-mile highway from Baghdad to Baqubah would now be a complicated and dangerous affair in which assassination or kidnapping would be a constant threat.

The decision to scale back plans for the post–2011 civilian mission was made by Biden and a faction of White House officials that included staff members of Obama's National Security Council, who were given primary responsibility for managing relations with Iraq, according to accounts from current and former U.S. officials who participated. A team led by State Department Deputy Secretary Thomas R. Nides was put in charge of reviewing and implementing the reductions, with support from State Department officials in Washington and Baghdad. Clinton, having lost the argument for a larger force, was briefed about the developments but left it to her subordinates to decide how the cuts would be implemented, several former and current administration officials said.

Biden's office declined to comment on the reductions, though former aides said the cuts reflected the prevailing view at the White House and on Capitol Hill: that a large civilian force in Iraq would not be sustainable once U.S. troops were gone.

"The president made the decisions on the military drawdown, and it was the president's directive that we were all executing," Nides said. "On the civilian side, the White House's big worry was the security of our people. Once the decision was made that we weren't going to have the authority to keep our military there — and even before it was made — we knew we not only couldn't afford to keep growing, but we had to reduce. At one point, we had the biggest civilian footprint in the world."

Administration officials insisted that a smaller, civilian-led force could continue to provide critical support for Iraq's transition, but the cuts were demoralizing to State Department and Pentagon officials who saw prized aid programs shrink or disappear. State Department officials tried to persuade other agencies, including the CIA, to split the costs of operating posts in Mosul and other provincial cities, but that idea withered as well.

"The robust presence we envisioned did not survive," recalled a former State Department official, speaking on the condition of anonymity to describe private White House deliberations about Iraqi policy. "Things kept getting whittled down. We'd come back from each meeting with bad news about the latest thing to get scrapped."

A Slow-motion Nightmare

Meanwhile, other programs intended to help Iraqis battle terrorism were facing a quiet death.

On Jan. 1, 2012, the first day after the U.S. troop era officially ended, 157 American military service personnel remained in Iraq as part of the State Department-run Office of Security Cooperation in Iraq. Pentagon and State Department officials sought and won authorization to expand the number by nearly twofold, from 157 to about 300, to be backed by a supporting cast of thousands of contract workers, according to documents and former officials.

Pentagon budget documents in early 2012 called the unit vital to counterterrorism efforts, facilitating the sharing of intelligence between military and civilian agencies in both the United States and Iraq. Among other missions, it provided support for Iraq's elite terrorism-fighting unit, known as the Counter Terrorism Service.

But the program began shrinking almost immediately after the troop withdrawal, former Pentagon officials remembered.

"It started going away," remembered Winters, the former deputy director.

A 2013 report by the Pentagon's inspector general said the cuts amounted to unilaterally slashing such programs to meet budget goals. The department implemented a "primarily top-down directed initiative in which cuts were made based on percentages and targets across assigned agencies without sufficient consideration of their differing missions and resources requirements," the report said.

An early casualty was direct U.S. support for Iraq's Counter Terrorism Service. The number of embedded U.S. advisers to the elite terrorist-fighting unit dropped from more than 100 before the military withdrawal to just two, according to Winters and other former Pentagon officials who served in Iraq.

Another key Pentagon program that helped the U.S. government collect and analyze intelligence about terrorist activities was scrapped. Charles Bova, who ran the program, said the scuttling of the project resulted in the loss of an important window into Iraq that could have provided Americans and Iraqis with "a better awareness of what al-Qaida in Iraq was up to."

A training facility in Kirkuk was shuttered, not only because of budget cuts but also because of resistance from Maliki's Shiite-led government, which had begun to push back against U.S. assistance programs in predominantly Sunni and Kurdish provinces. Immediately after the U.S. troop departure, Maliki began ordering the arrests of rival Sunni politicians while replacing U.S.-trained Iraqi generals with Shiite allies personally loyal to the prime minister. Some of the same Maliki appointees would later abandon their divisions as the Islamic State began its assault on Mosul.

Sunni protests against Maliki erupted in 2012 and, almost in tandem, the number of suicide bombings in Iraq started to rise. The terrorist predecessors of the Islamic State began gaining strength across Iraq, aided by the worsening sectarian tensions as well as the fighting next door in Syria, where the civil war gave jihadist leaders a cause and a safe haven in which to rebuild.

"None of us thought the problem was gone — we thought we were leaving a void there," Winters said. "We all expected that [al-Qaida in Iraq] would come back and get worse. But we didn't think it would happen that fast."

Worried that Iraqi security was unraveling, Clinton and other senior Obama advisers quietly lobbied Iraqi leaders to accept new forms of assistance unfettered by State Department legal and budgetary constraints. Beginning in late 2011, Clinton joined then-CIA Director David H. Petraeus and other White House officials in seeking to persuade Maliki to host a joint U.S.-Iraqi "fusion cell," consisting of intelligence experts and Special Operations forces from both countries, according to officials who participated in the talks. The White House also offered Maliki non-lethal surveillance drones to help track the movement of suspected terrorists, the officials said.

The Iraqis appeared open to both ideas but made no move to implement them. The possibility of U.S.-supplied drones in Iraq was nixed by Maliki after news of the offer leaked to the media. Both programs were eventually implemented, but only after waves of Islamic State suicide bombings began to threaten security in Baghdad.

"It was like one of those slow-motion nightmares," said Blinken, the State Department official. "We were moving our own system, trying to move Congress, trying to move the Iraqis. We saw this thing coming, we were acting on it, but the problem outran the solution we put into place."

The budget cuts did achieve one positive, and perhaps unexpected, result: a budget surplus. By May 2012, the State Department was sitting on $1.6 billion in funds that Congress had appropriated for Iraq, but which the department no longer intended to use there. Department officials had the option of redirecting those funds, and did so, shifting some of the money to other conflict zones, including Libya, according to public documents and former officials.

A large chunk of leftover cash was initially earmarked for the construction of a new diplomatic outpost in Benghazi, the restive Libyan city which Clinton had planned to visit in late 2012. That idea abruptly ended after the deadly Sept. 11, 2012, assaults on the Benghazi compounds that left four Americans dead.

Prized Targets

On June 4, 2014, the Islamic State, in a quick strike, captured Mosul. The black-flagged terrorists blew past Iraqi army defenders, aided in many cases by Sunni tribesmen who saw the jihadists as preferable to Maliki's Shiite-led government.

Whether the additional security assistance could have helped prevent the collapse of Iraq's security services is impossible to say with certainty. Many current and former administration officials, including some who strongly favored a residual U.S. troop presence, argue that Maliki's inept management of the military and repression of the country's Sunni minority inalterably weakened the country and made it vulnerable to collapse. If a few hundred Americans had been stationed in Mosul in 2014, these officials say, they might have become prized targets for the terrorist army that overran the city that summer.

"People have an illusion here," said Nides, the former State Department deputy secretary. "From a practical perspective, what you actually get is 20 people with a big security footprint. Are they going to be getting in their cars and driving around talking to tribal leaders? I don't think so."

In any case, the Islamic State's takeover prompted a rush by the Obama administration to restore military-led security assistance programs that had been quietly curtailed after the military drawdown. Within weeks, 475 U.S. troops were sent to advise Iraqi security forces. Today, the level is more than 10 times that. The concern over tight budgets has faded as well: Congress has appropriated billions of dollars to deal with the jihadist threat.

Clinton, the presidential candidate, responded to the crisis as well, putting forward a detailed plan for defeating the Islamic State. She has primarily blamed Maliki, the former Iraqi leader and her former partner during the transition, for the resurgence of the Sunni terrorists. Some of her proposed solutions have called for improving tribal liaisons and intelligence collection programs that were cut or abandoned three years earlier.

"We've got to do a better job of getting back the Sunnis on the ground," she told ABC News in an interview in 2015.

Clinton has stressed her experience and track record in the national security arena as a key selling point on the campaign trail, echoing themes from her memoir, "Hard Choices," which chronicled her experiences as secretary of state. The book came out a few weeks after Mosul fell to the Islamic State.

The book made news upon publication because of Clinton's admission that it was a "mistake" to have voted in 2002 to support the U.S. invasion of Iraq the following year.

On the rest of what happened in Iraq during her tenure as America's top diplomat, the 635-page book is silent.

Jeff Gerth, a senior reporter at ProPublica, previously worked as an investigative reporter at The New York Times. He has twice been awarded the Pulitzer Prize.

Joby Warrick covers national security and terrorism for The Washington Post. His book "Black Flags: The Rise of ISIS" was awarded the 2016 Pulitzer Prize for nonfiction.

ProPublica is a Pulitzer Prize-winning investigative newsroom. Sign up for their newsletter.

​