BAGHDAD (Reuters) - Months before the first shots are fired in the threatened battle to drive Islamic State out of Mosul, a dispute over Turkish troops in the area suggests that a struggle for influence over the future of Iraq’s second city has already begun.

Attention is turning toward Mosul, Islamic State’s stronghold in the north, after the jihadists were defeated in the western city of Ramadi by government forces last month.

Prime Minister Haider al-Abadi has vowed to retake Mosul this year as a “fatal and final blow” to Islamic State in Iraq. The city’s future is now in play, with Turkey a major contender for influence there along with Iraq’s Kurds, the government in Baghdad and possibly even Iranian-backed Shi’ite militias.

A NATO member and Sunni Muslim power with historic ties to Nineveh province where Mosul is located, Turkey is backing Iraqi Kurdish peshmerga forces, which see themselves as vital in any battle for the city, and is training a Sunni militia also expected to help retake the largest urban center under Islamic State control.

With the aid of these local allies, Turkey aims to expand its influence in the Sunni-populated province as Iraq splinters along communal lines, analysts say. Ankara also wants to counter Iranian influence in its southern, oil-producing neighbor.

“This is essentially a by-product of tensions with Iran,” said Sinan Ulgen, head of the EDAM think-tank in Istanbul.

The Iraqi military has been absent from Nineveh since collapsing in 2014 in the face of a major advance by Islamic State, and Baghdad is keen to reassert itself there.

Turkey meanwhile has close energy and trade ties with Iraqi Kurdistan and, despite its opposition to Kurdish PKK militants waging an insurgency against Ankara, supports the peshmerga as part of its wider interest in seeing the northern Iraqi region remain stable.

Peshmerga fighters, aided by Turkey, have pushed back Islamic State and extended their semi-autonomous northern region to include parts of Nineveh.

The stakes are high. The forces involved in previous operations to retake territory from Islamic State have had a say in how it is run afterwards and that is the calculation ahead of the expected battle for Mosul.

“Turkey sees Mosul and northern Iraq as a sphere of influence, a buffer zone, an area where it needs to have a military presence,” said Sajad Jiyad, a Baghdad-based political analyst who advises the government.

“They feel they need to be in control of that border area between Iraq, Turkey and Syria, or at least know what’s going on.”

While there is no indication the Turks intend to send significant numbers of troops, they have had bases in Iraqi Kurdistan since the 1990s, slowly increasing their presence in their fight against the PKK. That leaves Turkey well placed once the battle for Mosul begins.

The diplomatic row began last month after Turkey - at Abadi’s invitation, it said - sent 150 troops to the Bashiqa military base near Mosul to protect Turkish forces training the Hashid Watani Sunni militia to fight Islamic State.

After Baghdad complained to the U.N. Security Council, Turkey - a member of the U.S.-led coalition bombing Islamic State in Iraq and Syria - withdrew some troops to Kurdistan and said it would continue pulling out of Nineveh.

But Turkish President Tayyip Erdogan has rejected a total withdrawal and last week Iraq’s foreign minister said his country could respond militarily if forced.

Iraqi Finance Minister Hoshiyar Zebari, a senior Kurdish figure, later played down the dispute, saying it was “on its way to being solved.”

U.S. President Barack Obama spoke by phone with Abadi on Wednesday, saying Turkey should withdraw any military forces from Iraq not authorized by Baghdad. There was no immediate comment from Ankara.

HARD LINE

But with Abadi vowing to recover Mosul in 2016, competition for future control over the city of 2 million will intensify.

The Turks “are looking at the Americans and the Iranians, who already have a presence, and saying we should be doing something similar”, said Jiyad, the Baghdad analyst.

Abadi took a strong stance against the troop deployment, denying Turkish claims that Baghdad had approved it and accusing Ankara of acting in bad faith.

The Iraqi leader has battled an image of weakness and must deal with fractious coalition partners. His popularity could rise with the victory in Ramadi, but the Turkish troops issue could yet undermine him.

“He can’t be seen to be ignoring his partners, ignoring the coalition, ignoring the public... (otherwise) he could lose his coalition. He could face a vote of no confidence,” said Jiyad. “Abadi loses nothing by taking a hard line on Turkey.”

That hardline stance could reflect opposition to Turkey’s strengthening ties with fellow Sunni power Saudi Arabia, said Ulgen, the Istanbul analyst, but he did not foresee any direct confrontation.

“It’s more political, but of course it’s getting poisoned by higher sectarian tensions. That’s what’s making it harder to manage,” he said.

KURDS

Ties between Baghdad and Ankara have been tense for years and were not helped by Islamic State’s sweep across northern and western Iraq in 2014. Iraq blames Turkey for allowing foreign fighters to join the jihadists via Syria and says the Turkish consul in Nineveh had links to Islamic State, which Ankara denies.

Turkey’s move in 2014 to allow Iraqi Kurdistan to send oil exports by pipeline to a Turkish port also angered Baghdad.

Warm relations with Iraq’s Kurdistan Democratic Party (KDP), by contrast, have helped Turkey fight the Kurdistan Workers’ Party (PKK), which has staged an armed uprising against Ankara since 1984.

Citing an increase in PKK attacks, Turkey in July resumed bombing the militants’ bases in northern Iraq.

“With the fight against PKK reaching its peak, having troops in northern Iraq acts as a deterrent to further PKK incursions” into Turkey, said Ulgen, the Istanbul analyst, who predicted the forces would remain.

Erdogan last week denied any territorial ambitions, yet some think Turkish forces will not leave.

Adil Murad, a senior official in Iraqi Kurdistan’s Patriotic Union of Kurdistan, accused Turkey of manoeuvring to occupy part of Mosul once fighting there begins.

“The Turks dream about Mosul and consider it a Turkish province that was cut off after World War One,” he said. “This is unacceptable ... they are not the guardians of Mosul.”