WASHINGTON — The United States and Iraq have intensified talks to keep an ongoing American military presence in the country following the ouster of the Islamic State.

Both countries want to avoid a repeat of 2011, when American forces withdrew from Iraq after successfully weakening al-Qaeda and driving down violence in the country. Three years later, Iraq’s military collapsed in the face of an Islamic State invasion.

U.S. and Iraq have not yet determined the size and the composition of the force, which could change over time, according to two U.S. officials who did not want to be identified because they are not authorized to discuss the talks publicly.

The officials said no decisions about a long-term presence have been finalized, and the composition of a follow-on force would be determined by the Iraqi government.

“It’s kind of like what we were looking to do after 2011,” said James Jeffrey, the U.S. ambassador to Iraq at the time who has followed the issue closely.

It’s not clear that the United States will be able to avoid some of the political pitfalls in Baghdad that killed the agreement in 2011.

Iran holds considerable political sway in Iraq because both countries have populations that are majority Shiite Muslims surrounded by neighbors with Muslims from the Sunni sect. “The big issue is whether there will be pressure form Iranians for us to leave,” Jeffrey said.

Jeffrey, now an analyst at the Washington Institute for Near East Policy, said the size of the force would likely be less than the 5,500 troops there now.

More:Trump takes credit for ISIS defeats. Does he deserve it?

More:The U.S. bought weapons for Syrian rebels — and some wound up in the hands of ISIS terrorists

More:Iraq says its war against the Islamic State has ended

The mission of any future troop presence would be similar to what U.S. troops are doing currently: training Iraqi forces and helping with intelligence and surveillance, Jeffrey said. They are not involved in direct combat.

The presence of U.S. advisers and other support would help stabilize the military and avoid the type of catastrophe in 2014 when Islamic State, or ISIS, militants easily captured Mosul, Iraq's second-largest city, and other cities and towns as many of Iraq's soldiers fled.

Since then, U.S.-backed Iraqi forces have broken the Islamic State’s grip on territory and forced those militants who survived to escape into the desert.

“Despite these successes our fight is not over,” Defense Secretary Jim Mattis said last month. “Even without a physical caliphate, ISIS remains a threat to stability in the recently liberated areas, as well as in our homelands.”

ISIS may not hold territory but can create terror with bombings in Iraq and by plotting or inspiring attacks around the world.

Iraq’s government recognizes the threat and sees the need for more help from a U.S-led military coalition. Iraqi Prime Minister Haider al-Abadi declared victory over ISIS earlier this month but said terrorism remains a “permanent enemy.”

U.S. officials have echoed that. “I think we need to structure ourselves to be prepared for a long-term commitment to building partner capacity in this area,” Army Lt. Gen. Paul Funk told USA TODAY in October.

In 2011, talks on keeping U.S. troops in Iraq broke down over the issue of guaranteeing legal protections for the U.S. so they would not be prosecuted for crimes related to their use of force. Iraq’s government rejected the agreement amid political opposition to a long-term U.S. presence.

This time, U.S. and Iraqi officials hope to avoid a political standoff. Instead of a formal agreement that would need the approval of Iraq's parliament, the U.S. military said it could operate under an existing memorandum of understanding between the two countries, according to one of the U.S. officials.

The memorandum has been in effect since 2014, when American advisers were deployed to Iraq to help local forces battle ISIS.

Any agreement to keep American advisers in Iraq will provide a check on expanding Iranian influence in Baghdad, Jeffrey said.

Shortly after the Islamic State invasion of Iraq, Iran’s government rushed aid and support to Shiite militias fighting against the ISIS offensive. Iran has continued to back militias and holds sway over political leaders in Baghdad.