People pray in front of the Reina nightclub on Jan. 3 in Istanbul after a gunman killed 39 people on New Year’s Eve. Three recent assaults have served as a stark reminder of Turkey’s proximity to the war in neighboring Syria. (Bulent Kilic/AFP/Getty Images)

The attacks in Turkey came in rapid succession: twin bombs at a stadium, a Russian diplomat’s murder and then, just a few days later, a mass shooting at an Istanbul nightclub on New Year’s Eve.

The assaults, carried out over a three-week period beginning in December, were a stark reminder of Turkey’s dangerous proximity to the war next door in Syria, and the ways in which that conflict has steadily consumed Turkish domestic and foreign affairs.

Kurdish separatists attacked the Istanbul stadium, while the Islamic State asserted responsibility for the nightclub massacre, warning Turkey against military action in Syria. In Ankara, a police officer invoking the carnage in the Syrian city of Aleppo — but apparently working alone — gunned down the Russian ambassador on Dec. 19.

The turmoil in Syria has deepened Turkey’s political and social fault lines, brought violence to its cities and isolated it from traditional allies. Turkish troops are fighting and dying in battles with the Islamic State in Syria, and its relations with a number of countries, including the United States, are noticeably strained.

“Any efforts to address the conflict in Syria will boomerang back into Turkey’s domestic politics,” said Aaron Stein, senior resident fellow at the Atlantic Council’s Rafik Hariri Center for the Middle East.

Family members weep in Cayiralan, Turkey, during funeral prayers on Dec. 23 for a Turkish soldier who was killed with 15 others by Islamic State militants in al-Bab, Syria. (DHA-Depto Photos via AP)

Turkey shares a 500-mile-long border with Syria.

But the absence of any political solution “means we’re in for more cycles of violence,” he said, adding that “Turkey has no answers” for how to solve the myriad conflicts at home or in the region.

Turkey was one of the first countries affected by the Syrian conflict, taking in nearly 3 million refugees and leading calls for an international safe zone for civilians.

Turkey initially urged President Bashar al-Assad to refrain from cracking down on peaceful protests in 2011. But Assad’s heavy-handed response to the demonstrations prompted Turkish President Recep Tayyip Erdogan, who was prime minister at the time, to cut ties with the regime, and he soon threw his weight behind the Syrian opposition.

His decision further polarized Turkey, with his Sunni Muslim base rallying to the cause of the rebellion. His left-wing opponents objected to what they said was an adventurist foreign policy and called on Erdogan and his ruling Justice and Development Party to halt support for Syria’s Islamist rebels.

“Our position on Bashar al-Assad is clear: We don’t believe that a united and peaceful Syria is possible with him,” said a Turkish official, speaking on the condition of anonymity to discuss government matters.

But years later, Assad is still in power and Turkey is a regional outlier, spurned for its bullish diplomacy and alleged support for Syrian Islamic militants — a claim Turkish officials have strongly denied.

“The war in Syria has become Turkey’s greatest foreign policy challenge since the end of the Cold War,” said Soner Cagaptay, director of the Turkish Research Program at the Washington Institute for Near East Policy. “As a result of its failed attempt to oust the Assad regime, Ankara has the distinction of being hated by all major parties in the Syrian conflict, from the Kurds to [the Islamic State] to the Assad regime.”

In an attempt to break its isolation, Turkey has recently softened its rhetoric on Syria, and is now partnered with Russia — Assad’s ally — to restart peace talks and maintain a cease-fire.

“Turkey, in cooperation with Russia, brokered the evacuation of eastern Aleppo and a cease-fire in Syria,” the Turkish official said.

The planned peace talks, which will be held in the Kazakh capital, Astana, “are intended to make progress toward a political solution in the country,” the official said. “Turkey will attend the talks as a guarantor.”

But in a rare public admission, Deputy Prime Minister Numan Kurtulmus told the Turkish newspaper Hurriyet Daily News that Turkey should “correct its mistakes in Syria.”

“I am one of those who believes our policy on Syria made big mistakes,” Kurtulmus said in the interview this month.

While Turkey has pledged to roll back some of its more hard-line policies, its relations with the United States remain fraught with tension over Syria.

Turkey has openly opposed U.S. cooperation with Syrian-Kurdish militias in the fight against the Islamic State. The Syrian-Kurdish People’s Protection Units, or YPG, have carved out territory in northern Syria for a future Kurdish state, alarming Turkey, which is worried about the aspirations of its own Kurdish population.

Turkish officials say the YPG is indistinguishable from the Kurdish groups launching attacks inside Turkey, and to which security forces have responded with a devastating crackdown. The United States says the YPG is the most effective fighting force against the Islamist militants.

“We are your NATO ally,” Erdogan said, addressing the United States in a speech last month. “How on earth can you support terrorist organizations and not us?”

Turkey and the United States are NATO allies and strategic partners, the Turkish official said, but there are two sticking points. First, the two countries disagree over the extradition of Muslim cleric Fethullah Gulen to Turkey, where he is suspected of having masterminded a failed coup attempt last summer.

“The second issue is Washington’s support for YPG, the PKK’s Syrian franchise,” the official said. The PKK, or Kurdistan Workers’ Party, has been locked in a decades-long conflict with Turkey and has recently stepped up its attacks.

The shaky relations with the United States will probably force Turkey “to transition to a new model of security,” said Selim Koru, analyst at the Economic Policy Research Foundation of Turkey, an Ankara-based think tank. “Such a transition cannot be smooth.”

Turkey’s security has for decades been anchored in its alliance with NATO. But today, Turkey’s military, which helped the country weather previous national crises “is weakening,” Cagaptay said.

In the failed coup last summer, a faction in the military “tried to overthrow Erdogan, suggesting that even the military cannot be trusted as a unifying national institution in the current crisis,” he said.

In August, Turkish troops launched an offensive on the Islamic State-held town of Jarabulus in Syria. That offensive, named Operation Euphrates Shield, was backed by the United States. But Turkey has since moved unilaterally to battle the Islamic militants in the border town of al-Bab, where Turkish troops have met stiff resistance and scores of soldiers have been killed.

Turkey’s occupation of al-Bab would break the Islamic State presence on Turkey’s border but would also cut through territory claimed by Syrian Kurds.

“Operation Euphrates Shield is a milestone in [Turkey’s] foreign policy,” Koru said, adding that Turkey has only rarely occupied and held territory on its own.

But in al-Bab, “my understanding is that [the Islamic State] was better prepared for Turkish tanks than planners in Ankara expected,” he said.