The United States is trying to broker a compromise in which the Turks would not directly participate in the Mosul offensive but stick to training and perhaps medical and humanitarian support. In a visit to Turkey in recent days, Defense Secretary Ashton B. Carter said there was an agreement “in principle” between Turkey and Iraq, which the Iraqi government immediately denied. Iraq appears to want a commitment from the Turks that they will leave after Mosul is retaken.

Mr. Carter has said the United States is trying to balance “our respect for the sovereignty of Iraq” and “our respect also for Turkey’s historic role in the region.”

Turkey has a number of strategic reasons for maintaining a military presence in northern Iraq. It wants a bulwark against the Kurdistan Workers’ Party, or P.K.K., which is waging an insurgency in southeast Turkey and keeps bases in the mountains of northern Iraq. The P.K.K. fought in the battle for Sinjar, in northern Iraq, last year.

Turkey, a Sunni power, also says it wants to protect ethnic Turkmens and Sunni Arabs in northern Iraq and counter the presence of Shiite Iran, which is dominant in Iraq and controls several militias. More broadly, and in keeping with Mr. Erdogan’s vision of reclaiming Ottoman glory, Turkey wants to project influence in the region, in Iraq but also in Syria, where in August the Turkish military intervened to push the Islamic State out of the city of Jarabulus.

At times, Mr. Erdogan has seized on the issue of Mosul to highlight century-old grievances that linger from the end of World War I, when Western powers divided the former Ottoman lands of the Middle East. “We did not voluntarily accept the borders of our country,” he said.

He has also referred to a manifesto from the last Ottoman Parliament, as the empire crumbled, claiming Mosul as part of Turkey.

“Our most important task is to teach this to a new generation,” he said recently.

Mensur Akgun, the director of the Global Political Trends Center in Turkey, said that for Turks, “there is also an emotional side to the issue.” Referring to Mosul, Mr. Akgun said: “A century ago, that place was Turkey. A big geography was Turkey. It is committed in the memories that British and French imperialism was responsible.”