Defense Secretary Ashton B. Carter, left, shakes hands with Turkish President Recep Tayyip Erdogan in Ankara on Friday. (Turkish President Press Office/via European Pressphoto Agency)

Defense Secretary Ashton B. Carter said during a visit here Friday that Turkey should have a role in the campaign to retake the Iraqi city of Mosul from the Islamic State, a move that could put the United States at odds with Iraq as officials in Baghdad become increasingly hostile to any Turkish presence in their country.

“There’s an agreement there in principle, but now we have to work down to practicalities,” Carter told reporters before departing for the United Arab Emirates. Earlier in the day he met with Turkish President Recep Tayyip Erdogan, Prime Minister Binali Yildirim and Defense Minister Fikri Isik to discuss Turkey’s role in the fight against the Islamic State.

Carter’s suggestion came after Iraqi Prime Haider al-Abadi and Erdogan traded barbs over a contingent of roughly 500 Turkish troops, stationed north of Mosul, who have been training Kurdish peshmerga fighters and Arab militias since last year. The Iraqi government has said the Turkish garrison is unauthorized and has demanded that those forces leave. Recent protests in Baghdad called the Turkish presence an “occupation” force, according to an Associated Press report.

Carter declined to get into any specifics about what Turkish involvement in Mosul might entail, adding that any agreement for Turkey to participate in the campaign would have to be approved by the Iraqi government.

“I think that Iraq understands that Turkey is a member of the counter-ISIL coalition and that it will play a role in the counter-ISIL operations in Iraq,” Carter said, using an acronym for the Islamic State. “Turkey, as a neighbor in the region, has an interest in the ultimate outcome of the operations in Mosul.”

The campaign to retake Mosul began in earnest early Monday morning, but operations around the city have been underway for months as Iraqi, Kurdish and militia forces have moved to encircle the Islamic State stronghold. The city, considered the insurgent group’s capital in Iraq, fell in the summer of 2014 and since then has been fortified with improvised explosive devices, tunnels and booby traps in anticipation of an offensive to recapture it.

A senior U.S. defense official, speaking on the condition of anonymity to discuss plans, said Turkish officials said their forces could participate militarily or in a humanitarian role.

In the past week, Turkish and Iraqi officials met to discuss Turkey’s role in Iraq, and in the coming weeks the Pentagon hopes to facilitate and, if need be, mediate another meeting, the official said.

“It’s a matter of implementation and what the appropriate role is for the Turks,” the official said. “I think that we’re hopeful there is a way to build them into the process, but that’s something we really need to feel out with the Iraqis.”

In recent weeks Turkish forces, alongside Syrian opposition fighters, have retaken a number of towns in northern Syria from the Islamic State, including Dabiq, one of the group’s key strongholds.

On Thursday, Turkish jets reportedly struck Syrian Kurdish fighters, and reports said 200 may have been killed. Following Carter’s visit to Turkey, the Pentagon chief said he had not spoken to his Turkish counterparts about the strike and could offer few details.