ANKARA (Reuters) - Turkey and Iraq have reached an agreement in principle that could eventually allow a Turkish role in the campaign to retake Mosul from Islamic State, U.S. Defense Secretary Ash Carter said on Friday after talks with President Tayyip Erdogan.

U.S. Defense Secretary Ash Carter, accompanied by Turkey's Defense Minister Fikri Isik (R), talks to media as he visits Turkish Parliament which was partly damaged during the July 15 coup attempt, in Ankara, Turkey, October 21, 2016. REUTERS/Adem Altan

Erdogan has previously voiced frustration that NATO member Turkey has not been more involved in the U.S.-backed assault on the Iraqi city, once part of the Ottoman empire and still seen by Turkey as firmly within its sphere of influence.

Iraq, meanwhile, views Turkish military moves on its territory with apprehension, and any agreement on Mosul would defuse a major source of tension between the neighbors.

Carter made clear that details on Turkey’s potential role in the unfolding Mosul campaign still needed to be hammered out and a senior U.S. defense official noted non-military assistance was also a possibility.

“That will have to obviously be something that the Iraqi government will need to agree to and I think there’s agreement there in principle,” Carter told reporters traveling with him in Turkey, voicing his own conditional support for some type of Turkish role in Iraq.

“But now we’re down to the practicalities of that ... and that’s what we’re working through.”

Turkey has been locked in a row with Iraq’s central government over the presence of Turkish troops at the Bashiqa camp near Mosul, where it has trained thousands of forces.

Erdogan has warned of sectarian bloodshed if the Iraqi army relies on Shi’ite militia fighters to retake the largely Sunni city of Mosul.

Turkish Defence Minister Fikri Isik, who met Carter, also said there was agreement in principle on Turkish involvement in “determining the future of Mosul” and that he had agreed with his U.S. counterpart on the need for the three countries to work together to reduce tensions between Ankara and Baghdad.

“We will work jointly on Turkey’s participation in the Mosul campaign and on Turkey being at the table in the process after that,” Fikri said in an interview on state broadcaster TRT.

“LEGITIMATE CONCERNS”

Carter also met Turkish Prime Minister Binali Yildirim, who said earlier this week that Turkish jets would be deployed at some point in the offensive to retake Mosul, the last big stronghold held by Islamic State in Iraq.

The push to capture it is expected to become the biggest battle in Iraq since the 2003 U.S.-led invasion. Mosul is around five times the size of any other city Islamic State has held.

The senior U.S. defense official, who spoke on condition of anonymity, said the United States recognized that Turkey had legitimate security concerns over the outcome of the Mosul campaign and expressed hope that Turkish and Iraq officials could meet next week.

The United States was also raising the issue of a Turkish role in Mosul in its regular talks with Iraqi leadership.

“We will talk about, in an aspirational way, some of the things that the Turks could do,” the U.S. official told reporters traveling with Carter, noting the possibility of non-military support, including medical and humanitarian assistance.

Even once questions about Mosul are resolved, the United States and Turkey still have major hurdles to overcome in their joint approach to battling Islamic State in Iraq and Syria.

Turkey has been angered by Washington’s support for Kurdish militia fighters battling Islamic State in Syria.

The United States sees the Syrian Kurdish YPG as a useful ally in the fight against the jihadists. But Turkey views them as a hostile force, an extension of Kurdish militants who have waged a three-decade insurgency on its own soil.