Turkey’s army last week filed for the retrial of the hundreds of officers who were imprisoned in an alleged attempt to topple Prime Minister Recep Tayyip Erdoğan, aligning both against a judiciary the premier has accused of smearing his administration.

The military, which sees itself as the guardian of Turkey’s secular traditions and has taken power thrice in its republican history, was long seen by Erdoğan as his foe. The Islamist prime minister, who has been in power for almost eleven years, was in turn seen as orchestrating the conviction of hundreds of serving and former military officers for allegedly plotting a coup against him.

The army has now seized on Erdoğan’s newfound criticism of the courts to petition for a retrial.

Battling corruption charges against his government, Erdoğan said this weekend, “There are members of the judiciary who are seeking to smear innocent people.”

He had sacked the policy officers who were involved in a graft investigation that saw the arrest of two members of his cabinet as well as the sons of his interior minister and curbed the judiciary’s power, preventing a second round of detentions when newly appointed police chiefs refused to carry out raids.

Erdoğan previously described the corruption probe as a “dirty operation” and claimed that the involved prosecutors were trying to form a “state within a state,” apparently in reference to followers of the former imam Fethullah Gülen who has been increasingly critical of Erdoğan’s policies.

The preacher, who lives in Pennsylvania, is among the most influential Turkish opinion leaders. He shares Erdoğan’s moderate Islamism but has been critical of his foreign policy, especially Turkey’s estrangement from Israel and its support for the rebellion against President Bashar al-Assad’s regime in Syria. He further distanced himself from Erdoğan this summer when millions of mainly secular Turks took to the streets to protest against what they saw as the prime minister’s dictatorial rule.

The army’s petition for a retrial puts Erdoğan in a tough spot. By rejecting it, he would implicitly redeem the very prosecutors and judges who locked up his perceived enemies in the military but whom he now considers part of a “gang that is establishing itself inside the state.” If the prime minister supports the army’s petition, on the other hand, he would not only fuel allegations that the coup trials were politically motived in the first place; he would rehabilitate an institution he has fought for the better part of a decade and further undermine Turkey’s legal state.