Istanbul (CNN) For months, the US has been building up an alliance in the Middle East aimed at dislodging ISIS from its strongholds in both Iraq and Syria.

But these efforts have been complicated in recent weeks by one of Washington's oldest allies in the region: Turkey.

The Turkish government is lashing out against factions currently battling ISIS. Ankara has been engaged in a very public war of words with the government in Iraq. At the same time, the Turkish military has been bombing US-backed Kurdish militants in Syria.

Part of this policy stems from Turkey's unenviable position, living alongside two of the bloodiest, most destabilizing conflicts the Middle East has seen in a generation.

Iraq

Days before the start of the week-old Iraqi offensive to drive ISIS out of the northern Iraqi city of Mosul, Turkey's President issued an unusual public demand to join the military operation.

"We have to take part in the Mosul operation," said Recep Tayyip Erdogan.

The Turkish announcement drew angry rebukes from the Iraqi central government, and Iraqi Prime Minister Haider Al-Abadi openly accused Turkey of violating Iraqi sovereignty.

"The Mosul battle is an Iraqi battle and the ones who are conducting it are Iraqis," Abadi later added.

Why Mosul matters Since Mosul's capture by ISIS fighters in June 2014, Mosul has been a vital stronghold for ISIS. The largest city under ISIS control in Iraq and Syria, it was the city from which the group first declared the establishment of its so-called caliphate. Since then, ISIS has gradually lost its other Iraqi cities -- Ramadi, Tikrit and Falluja -- to government forces. About 1 million people are estimated to remain in Mosul, once a cosmopolitan trade hub of 2 million residents.

Turkish officials have used several arguments to justify their inclusion in the Mosul offensive.

One revolves around the fear of further sectarian conflict between Mosul's predominantly Sunni population and the Shi'ite-dominated military forces of the Iraqi government.

"If we accept Mosul's current destiny, there will be a Sunni-Shia struggle," Erdogan said in a speech October 18.

But behind the scenes, analysts say there is ongoing rivalry for influence in Iraq between Turkey and another regional powerhouse: Iran.

"Turkey and Iran have a tradition of silently competing with each other," explained Ahmet Han, associate professor of international relations at Kadir Has University.

"The difference is that Turkey is speaking a lot and very loudly, but Iran is not," Han added.

Last year, Turkey sent several hundred Turkish soldiers armed with tanks and artillery pieces to a base in Bashiqa, near Mosul. Iraq protested, saying it had not given permission for such a move.

And Turkey's claims that it helped the Peshmerga by providing tanks, artillery and troops in weekend battles around Bashiqa drew another angry outburst from Iraq's Prime Minister.

"We don't want Turkish military forces on the ground," Abadi said Monday. "The Turkish claim that they participated in the war is untrue."

Meanwhile, majority Shiite Iran continues to enjoy influence within the Iraqi government, and among a number of Shiite militias that have been trained by the Iranian military.

In speeches before crowds of supporters, Erdogan has also argued that Turkey should determine Mosul's future, based on the fact that the city was ruled more than a century ago by the Ottoman Empire.

Photos: The clock tower of the Dominican Mission Church in Mosul, built in the 1870s, was a gift from Empress Eugenie of France. The ancient city is almost 3,000 years old and has historically been important for trading. Located in northern Iraq near the borders of Syria and Turkey, it's situated on the Tigris river and set amid rich oil fields. Hide Caption 1 of 26 Photos: This print of Mosul is from the 1930s, when Iraq was a kingdom occupied by the British. Hide Caption 2 of 26 Photos: Among the many activities on the Tigris River in Mosul was wool washing. Hide Caption 3 of 26 Photos: The souks, or markets, of Mosul hummed with activity every day. Hide Caption 4 of 26 Photos: The famous leaning minaret of Mosul's 12th-century Great Mosque of al-Nuri towers in the background of this photo taken in the 1930s. Hide Caption 5 of 26 Photos: Lady Surma was the sister of the patriarch of the Assyrian Christian church in Mosul and became an ambassador for her people. Hide Caption 6 of 26 Photos: The British writer Agatha Christie arrived at this railway station in Mosul. Agatha Christie spent time in Mosul in the early 1950s while her husband, the archaeologist Max Mallowan, excavated the ancient site of Nimrud. Hide Caption 7 of 26 Photos: Two women look out over the Tigris from the 12th-century Bashtabiya Castle, a big part of Mosul's identity. ISIS destroyed the castle last year, according to the Iraqi Ministry of Tourism and Antiquities. Hide Caption 8 of 26 Photos: President Saddam Hussein waves to supporters from the balcony of the mayor's office in Mosul on a trip to see how farmers were faring under international sanctions. Hide Caption 9 of 26 Photos: A boy begs for money in 1996. By then, Iraq was reeling under punishing international sanctions and widespread corruption. Hide Caption 10 of 26 Photos: The mosque of the prophet Yunus (Arabic for Jonah from the Bible) stood on one of the two most prominent mounds of Nineveh's ruins and served at one time as an Assyrian Church. It contained Jonah's tomb and was destroyed by ISIS in 2014. Hide Caption 11 of 26 Photos: In this 2001 photo, a man stands before the Great Mosque's minaret, which leans like the Tower of Pisa and is nicknamed "al-Habda," or "the hunchback." Hide Caption 12 of 26 Photos: Kurds mingle with the crowds in central Mosul in 2002, just a few months before the U.S.-led invasion of Iraq. Hide Caption 13 of 26 Photos: Children at a school in Mosul in 2002. ISIS developed its own curriculum after it took control of the city in 2014. Hide Caption 14 of 26 Photos: Crowds gathered in Mosul in February 2003 to protest US threats of invasion. Hide Caption 15 of 26 Photos: Kurdish children play on a broken ferris wheel in Mosul, a month before the invasion of Iraq in 2003. Hide Caption 16 of 26 Photos: A teenage boy tends to a herd of sheep on the outskirts of Mosul in 2003. Hide Caption 17 of 26 Photos: The lake in Saddam Hussein's palace was off-limits to Mosul's ordinary citizens until the dictator was toppled in April 2003. Hide Caption 18 of 26 Photos: The University of Mosul is the second-largest in Iraq and boasted a rich tradition of learning. ISIS militants destroyed thousands of books and manuscripts housed at the university and developed a new curriculum. Hide Caption 19 of 26 Photos: Fierce clashes erupted in Mosul in the summer of 2003, and US soldiers found themselves in the midst of urban warfare. Hide Caption 20 of 26 Photos: Iraqi police patrolled the city in 2005. Hide Caption 21 of 26 Photos: This children's clothing factory in Mosul was operating after reconstruction efforts in 2007. Hide Caption 22 of 26 Photos: Moslawis walk past trash strewn about a busy market area in Mosul in 2009. Hide Caption 23 of 26 Photos: ISIS fighters parade down a main road in a commandeered Iraqi security forces vehicle after the militant group took control of Mosul in June 2014. Hide Caption 24 of 26 Photos: ISIS destroyed ancient Christian shrines and churches like this 13th-century church in the Assyrian town of Telskuf, not far from Mosul in the Nineveh plains. Hide Caption 25 of 26 Photos: Iraqis displaced from ISIS-controlled towns and villages take shelter at this camp in Qayyarah, a few miles south of Mosul. Aid workers warn an assault on Mosul could trigger an exodus of catastrophic dimensions. Hide Caption 26 of 26

That argument rankles many Iraqis.

But analysts say it finds a willing audience among some Turks who are still bitter about the collapse of the Ottoman Empire during World War I.

"Mosul is in the collective consciousness of all Turks," explained political scientist Soli Ozel.

"It is usually believed that no matter what your political lineage is, it should rightly belong to Turkey."

Syria

While they frequently speak about Mosul, Turkish officials have not been nearly as vocal about a series of attacks carried out by Turkish forces over the last week in neighboring Syria.

On Thursday, the Turkish Armed Forces announced in an email that warplanes carried out dozens of airstrikes against suspected Kurdish militia targets in northern Syria.

"As a result of the operation, 160 to 200 PKK/PYD terror organization members were neutralized," the military claimed, referring to the Kurdistan Workers Party and its Syrian affiliate, the PYD.

PYD officials tell CNN the Turkish bombing raids killed far fewer people.

"The Turkish state numbers of the casualties are a lie," said Fawzi Suleiman, a spokesman for the Syrian Kurdish fighters.

He said public funerals have been held for 17 people killed by the Turkish air and artillery strikes.

In subsequent days, the Turkish military announced it used artillery to support Syrian Arab fighters advance deeper into Kurdish-controlled territory.

For 30 years, PKK fighters have waged a guerrilla war against the Turkish state.

The unexpected rise several years ago of a Kurdish militia linked to the PKK in neighboring Syria caused great alarm in Turkey.

Turkish officials have denounced the US for providing military assistance to this Kurdish faction, even though it has proven to be one of the most successful fighting forces against ISIS in Syria.

After the Turkish aerial assault last week, Kurdish officials accused Turkey of helping ISIS.

"The main reason Turkey is shelling us is because Turkey wants to support ISIS," Zuhat Kobani, a spokesperson for the PYD in Belgium, told CNN.

In fact, Turkish security forces have spent the last several months targeting suspected ISIS militants both at home and abroad.

But analysts say Turkish officials are much more worried about the possible establishment of a Kurdish statelet in Syria.

The PKK "is deemed as an existential threat," said Han.

As part of its effort to project power onto the increasingly complex Syrian battlefield, Turkish troops moved across the border into northern Syria last August.

To this day, the Turkish military continues to maintain a presence along a band of Syrian territory.

Trouble at home

Turkey has good reason to feel vulnerable. The conflicts in Iraq and Syria have spilled over into Turkey, contributing to a surge in violence on the home front.

The country struggles with the burden of hosting millions of Syrian and Iraqi refugees.

ISIS militants have mounted a series of devastating bombings over the last several years that have claimed the lives of hundreds of Turks.

Meanwhile, Turkish security forces continue to clash on a nearly daily basis with PKK militants, mostly in predominantly Kurdish parts of southeastern Turkey.

Finally, the country is still reeling from a bloody, but failed attempt at a military coup last July.

The instability has contributed to a sharp down-turn in Turkey's once vibrant tourism industry. Turkey's currency fell to record lows week.

The political, security and economic woes come as Turkey's President has embarked on a very public campaign to rewrite the constitution to grant him more powers.

"A lot of this is posturing for domestic political purposes," says Soli Ozel, an international relations expert at Istanbul's Kadir Has University.

Some observers note that rhetoric aimed at Turkish supporters does not translate well to audiences across the border in Syria and Iraq.

"Turkey's unreasonable 'irredentist rhetoric' is all for domestic consumption," wrote columnist Mustafa Akyol.

"A problem of those who rule Turkey today is being unable to comprehend the global impact of what they say to cheer up their emotional base."