U.S. soldiers from the 82nd Airborne Division fire artillery in support of Iraqi forces fighting Islamic State militants from their base east of Mosul, April 17, 2017. The U.S. and Iraq are in talks to keeping American troops in the country after the fight against the Islamic State group is concluded.

BAGHDAD — Prime Minister Haider al-Abadi is in talks with the Trump administration to keep American troops in Iraq after the fight against the Islamic State group in the country is concluded, according to a U.S. official and an official from the Iraqi government.

Both officials underlined that the discussions are ongoing and that nothing is finalized. But the talks point to a consensus by both governments that, in contrast to the U.S. withdrawal in 2011, a longer-term presence of American troops in Iraq is needed to ensure that an insurgency does not bubble up again once the militants are driven out.

"There is a general understanding on both sides that it would be in the long-term interests of each to have that continued presence. So as for agreement, yes, we both understand it would be mutually beneficial. That we agree on," the U.S. official said.

Both officials spoke on condition of anonymity in line with regulations.

The talks involve U.S. Secretary of Defense Jim Mattis and Iraqi officials over "what the long-term U.S. presence would look like," the American official said, adding that discussions were in early stages and "nothing has been finalized."

U.S. forces in Iraq would be stationed inside existing Iraqi bases in at least five locations in the Mosul area and along Iraq's border with Syria, the Iraqi government official said. They would continue to be designated as advisers to dodge the need for parliamentary approval for their presence, he said.

He said al-Abadi is looking to install a "modest" Iraqi military presence in Mosul after the fight against the Islamic State group is concluded along with a small number of U.S. forces. The forces would help control security in the city and oversee the transition to a political administration of Mosul, he said.

The U.S. official emphasized that there were no discussions of creating independent American bases in Iraq, as such a move would require thousands more personnel. He said the troops levels would be "several thousand ... similar to what we have now, maybe a little more."

Currently, the Pentagon has close to 7,000 U.S. troops in Iraq, many not publicly acknowledged because they are on temporary duty or under specific personnel rules. The forces include troops training Iraqi forces, coordinating airstrikes and ground operations, and special forces operating on the front lines.

The news comes as Iraqi forces are struggling to push IS fighters out of a cluster of neighborhoods in western Mosul that mark the last patch of significant urban terrain the group holds in Iraq, nearly three years after the militants overran nearly a third of the country.

Such an agreement would underscore how the fight against IS has drawn the U.S. into a deepening role in Iraq.

At the height of the surge of U.S. forces in 2007 to combat sectarian violence that nearly tore Iraq apart, there were about 170,000 American troops in the country. The numbers were wound down eventually to 40,000 before the complete withdrawal in 2011.

The U.S. intervention against the Islamic State group, launched in 2014, was originally cast as an operation that would largely be fought from the skies with a minimal footprint on Iraqi soil. Nevertheless, that footprint has since grown given Iraqi forces' need for support.

During a visit to Iraq in February, Mattis and Lt. Gen. Stephen Townsend, the top U.S. commander in Iraq, described an enduring partnership between the U.S. and Iraq.

"I imagine we'll be in this fight for a while and we'll stand by each other," Mattis said.

Townsend, who was standing by Mattis, declined to say how long the United States will stay in Iraq. But, he said, "I don't anticipate that we'll be asked to leave by the government of Iraq immediately after Mosul." He added, "I think that the government of Iraq realizes their very complex fight, and they're going to need the assistance of the coalition even beyond Mosul."

The talks over a longer-term U.S. presence has greatly concerned Iran, which in turn is increasing support to some of Iraq's Shiite militia forces, said Jafar al-Husseini, a representative from Kataib Hezbollah, an Iraqi Shiite militia group with close ties to Iran.

"Iraq's security forces and the Popular Mobilization Forces (mostly Shiite militia groups) have the ability to protect (Iraq's) internal roads and borders, so why is al-Abadi using American security partners?" al-Hussein asked.

Al-Abadi has long struggled to balance Iraq's dependence on both the U.S. and Iran. Both countries are key security and economic partners for Iraq, yet are often at odds with each other when it comes to regional politics and security in the greater Middle East.

Over the nearly three-year-long fight against IS, Iraqi forces closely backed by the U.S.-led coalition have retaken some 65 percent of the territory the extremists once held in the country, according to the U.S.-led coalition. But Iraq's military is still in the process of rebuilding and reorganizing after it was largely gutted by widespread corruption under former Prime Minister Nouri al-Maliki.

___

Klapper reported from Washington. Associated Press Writer Lolita C. Baldor in Washington contributed to this report.