Before Turkey took an authoritarian turn under President Recep Tayyip Erdogan, many thought that the former head of the Justice and Development Party (AKP) would go down in history as the leader who finally tamed Turkey’s military and resolved the country’s decades-long conflict with the Kurds. Such hopes now seem outrageously misplaced. Erdogan has given the military a blank check to wage war against Kurdish insurgents and has struck a cozy alliance with the generals. For his part, Erdogan must believe he is killing several birds with one stone. The military campaign against the Kurds both weakens the country’s largest minority, which recently dealt a blow to Erdogan’s ambitions for unchecked power, and consolidates his power among the country’s nationalists. Along the way, Erdogan might mend ties with the country’s long-estranged military, which could come in handy as his domestic and international opponents begin to encircle him. But for Erdogan, empowering the military could be risky. There are even those within his close circle, including some of his advisers, who fear that the president is riding a tiger that, after years of harsh treatment under the ruling AKP, is all the wilder and more vengeful.

The military has reason to hold a grudge. For much of Turkish history, it has held significant sway over political affairs, staging four outright coups, forcing several other political leaders to resign, and acting as an unquestioned guardian of secular democracy. Since coming to power in 2002, the AKP has whittled away at the generals’ influence, which has left Turkey’s once omnipotent armed forces weak and divided. To meet EU accession criteria, Ankara implemented measures to bring the military within civilian control. It limited the jurisdiction of military courts in favor of civilian courts, and it started to play an active role in the appointments of top military commanders. A further blow to the military’s standing came in April 2007, after the military posted to its website an ultimatum (later called the “e-coup”) to warn the AKP against backing Abdullah Gul, who previously belonged to an Islamist party and whose wife wears a headscarf, for the presidency. The public and the AKP were outraged, and Gul was elected. The military’s attempt to intervene against a popular party dealt a serious blow to its standing in society, and in an early vote held right after the e-coup, the AKP increased its vote share by 13 percent.

Around the same time, the government’s then allies in the judiciary, the Gulenists (an Islamic movement linked to the U.S.-based cleric Fethullah Gulen), launched several criminal investigations of military officers. Under the Ergenekon and Sledgehammer prosecutions, which alleged a conspiracy to overthrow the AKP government, scores of generals were imprisoned and hundreds of retired military officers detained. The clash between the AKP government and the military culminated in the mass resignation of Turkey’s military high command in late July 2011, marking, as the Turkey expert Henri Barkey called it, “the day the military threw in the towel.”

Soldiers stand at attention during a ceremony at the mausoleum of Mustafa Kemal Ataturk in Ankara, November 2014. Umit Bektas / REUTERS

Of late, however, the military seems to be experiencing a reversal of fortune. Since Necdet Ozel, an Erdogan loyalist, became military chief of staff after his predecessor resigned in protest, Erdogan and the armed forces have had somewhat improved ties, at least at the top levels. But the real thaw came when the Gulenists in the judiciary launched a corruption investigation that implicated Erdogan’s family and his close circle. Erdogan saw the military as a potential ally in what would become an all-out war against the Gulenists, his one-time partner. Following a statement from one of Erdogan’s close advisers, the military filed a complaint with the judiciary demanding a retrial of the defendants in the Sledgehammer case. The court then dismissed the whole case, arguing that the evidence was “fabricated,” and released the generals who had been jailed. The latest sign that the AKP and the military are back in each other’s good graces was the attendance of Hulusi Akar, the chief of the general staff, at Erdogan’s daughter’s wedding as one of the witnesses at the ceremony.

The recent breakdown of the cease-fire between the state and the Kurdistan Workers’ Party (PKK) has removed another sticking point in military-government relations. The military has always opposed the peace talks with the PKK and has accused the government of turning a blind eye to PKK activities in the Kurdish region. In 2014, military officials applied to carry out 290 operations against the PKK in the southeast. The government approved only eight, which was a sore spot between the two. Resumption of the fighting between the state and the PKK in the summer of 2015, therefore, paved the way for a closer alliance between the military and the government. The chaos engulfing Syria and Iraq and the tension between Turkey and Russia also contributed to the military’s comeback as an internal and external power broker. Both Erdogan and the pro-government media that once hailed the criminal cases against the military as a major victory for democracy are now praising the “heroic efforts of the armed forces” in countering Turkey’s domestic and international foes. In a grand gesture to his new allies, Erdogan defended secularism following a call from his mentor, Ismail Kahraman, to drop all references to secularism in Turkey’s constitution.

Erdogan is clearly betting that these gestures will keep a subdued military in line, but he is playing with fire; some fear the military might revert to its old habit of intervening in political processes if it sees an opportunity. In fact, the military might be down, but it is not out. It certainly retains considerable institutional autonomy. Kemalism, the founding ideology of the republic that has served for decades as a bulwark against Islamism and Kurdish separatism, still forms the ideological core of the curriculum at military high schools and academies. The only references to Islam at the academies is in the context of Ataturk. The military has even resisted calls from government circles to allow the enrollment in military academies of graduates from imam-hatip schools, vocational schools that educate state-employed imams and preachers. The military believes that such students might start the spread of religion in the ranks of the Turkish Armed Forces and lead to greater government control over the military. The defense budget remains largely immune to civilian oversight, and the military handles its own personnel management. Tellingly, the chief of the general staff is not subordinate to the minister of defense.

Turkish army commandos walk on a snow-capped summit in the mountains near the southeastern Turkish town of Sirnak, February 2008. Fatih Saribas / REUTERS

For all this, the military does not seem particularly interested in intervening in the political processes, at least for now. After the public’s reaction to the e-coup, it seems to prefer to stay out of politics. The general staff recently issued a strongly worded statement categorically denying allegations from pro-government circles that the military was planning a coup. It further threatened legal action against those media outlets covering the news. The military has always relied on public support when it decided to intervene in politics. The 1980 military coup, the bloodiest military takeover in Turkish history, for instance, was highly supported by the public, which viewed military intervention as necessary to restore stability. But today, the military knows full well that any intervention against Erdogan and his AKP, which received almost 50 percent of the vote in the latest election, would win little public backing and crush the military’s efforts to reclaim its standing in society.

As unlikely as a coup might be for now, there is still a scenario in which the military might intervene. Fourteen years of AKP rule has somewhat softened the military’s stance on secularism, but Kurdish separatism still remains the armed forces’ redline. The military might act if fighting between the PKK and the state spirals out of control, if mass violence in western urban centers leads to a security collapse and a major economic downturn, and if the government becomes increasingly authoritarian. Such circumstances could trigger massive antigovernment protests. If Erdogan responds with a brutal police crackdown and more chaos and bloodshed ensues, there could be growing public demand for the generals to take action. Even under these dangerous and undesirable scenarios, the generals would probably prefer to intervene by political rather than military means in pressuring the government to resign. Turkey has come too far in its political and economic evolution to be governed by a military junta.

But until then, the military and government are likely to remain on good terms. It is essential, however, to highlight the tactical nature and limitations of this alliance. Their interests might be aligned for now, but they still disagree on many issues. Erdogan’s increasing authoritarianism, his frequent zigzags on the Kurdish question, and his Middle East–focused and aggressive foreign policy have alienated Turkey’s traditional Western allies and raised eyebrows within the ranks of the armed forces.

Erdogan has not let down his guard against the military, either. The government’s decision to detach the Gendarmerie General Command, Turkey’s paramilitary rural police force, from the general staff of the Turkish Armed Forces and attach it to the Ministry of the Interior was an attempt to fill Gendarmerie ranks with AKP supporters and counterbalance the military. But ultimately it is the Kurdish question that will determine not only the future course of this marriage of convenience but also the military’s role in Turkish politics.