IMAGINE a country with NATO’s second-largest army that counts Iraq, Iran and Syria as neighbours and is encircled by the Aegean, the Black Sea and the Mediterranean—but has nobody to command its navy. Just such a situation looms in Turkey after this week’s resignation of Admiral Nusret Guner, the number two in the navy who was expected to take over when its incumbent head steps down in August. There are no other qualified candidates, not least because more than half of Turkey’s admirals are in jail, along with hundreds of generals and other officers (both serving and retired), all on charges of plotting to oust Turkey’s mildly Islamist Justice and Development (AK) government.

Admiral Guner’s resignation came after prosecutors claimed that 75 naval officers being tried for allegedly running a sex-for-secrets ring had planted a spy camera in his teenaged daughter’s bedroom. In an emotional speech the admiral said he believed in his colleagues’ innocence.

The series of cases known as Ergenekon has left Turkey’s once omnipotent armed forces weak and divided. At last count one in five Turkish generals, including Ilker Basbug, a former chief of the general staff, was behind bars. This ought to be a triumph for Turkish democracy. But the trials are dogged by claims of spiced-up evidence and other discrepancies.

The families of over 250 defendants given long prison terms in September 2012 in another alleged coup plot, Sledgehammer, are taking their case to the UN Human Rights Council. They insist the evidence was doctored. Independent forensic experts back their claims. Jared Genser, a lawyer based in Washington, DC, who has worked for such luminaries as Vaclav Havel and Desmond Tutu, says he agreed to act for the Sledgehammer defendants because he “firmly believes” in their innocence and because the evidence against them “was demonstrably forged”.

Some point fingers at a powerful Muslim group led by Fethullah Gulen, a moderate Turkish cleric living in self-imposed exile in Pennsylvania. The generals hounded the Gulenists after they ejected Turkey’s first Islamist prime minister, Necmettin Erbakan, in 1997. The Gulenists have made a comeback under AK and are said to have infiltrated the police and judiciary.

Turkey’s prime minister, Recep Tayyip Erdogan, shares some doubts, even though he has cut down the generals’ influence during his decade in power. “These operations against the army are affecting morale. There are 400 serving and retired officers in jail. At this rate we will have no officers left to appoint to command positions,” he complained in a recent interview. As clashes with the Kurdish separatist PKK continue despite new peace talks and the conflict in Syria threatens to spill over the border, Mr Erdogan is right to be worried.

Yet even as the prime minister seeks to distance himself from the Ergenekon case, some claim that he has struck a cosy alliance with the army. The chief of the general staff, Necdet Ozel, who owes his rise to the resignation in 2011 of his predecessor in protest at Ergenekon, is fiercely loyal. Mr Erdogan rushed to his defence in December 2011 after the Turkish air force had rained bombs on Kurdish civilians who were apparently mistaken for PKK rebels as they slipped into Turkey from Iraq. Some 34 Kurds, mostly teenagers, died. A parliamentary commission investigating the affair has run into claims of a cover-up. Not a single head has rolled.

It may be that the still-popular Mr Erdogan feels that the army is fully under his control. The National Security Council through which the generals used to bark orders to nominally civilian governments has been reduced to a symbolic role. After constitutional reforms were approved in a 2010 referendum, soldiers began to be tried in civilian courts. “Erdogan sees the army as his boys,” comments Henri Barkey, a professor of international relations at Lehigh University in Pennsylvania.

Yet for all their recent setbacks the generals still retain considerable sway. The defence budget remains largely immune to civilian oversight. The chief of the general staff is not subordinate to the minister of defence. And an internal service law that allows the army to intervene in politics remains in place.

Indeed, the idea that some officers may have been conspiring to topple the AK government is not far-fetched. In 2007 the army tried unsuccessfully to stop Abdullah Gul, a former foreign minister, from becoming Turkey’s president because his wife wears the Islamic headscarf. In 2008 the generals egged on the constitutional court to ban AK on flimsily documented charges that it was seeking to impose sharia law. In the event the case was dismissed by a single vote. As for Ergenekon, “even in the absence of tampered evidence, there is sufficient proof of coup plotting to send scores of generals to jail,” argues Orhan Kemal Cengiz, a human-rights lawyer who has studied the case.

Turkey’s army has overthrown no fewer than four governments since 1960. The bloodiest coup came in 1980, when 50 people were executed, 500,000 were arrested and many hundreds died in jail. Yet millions of Turks, who have long revered the armed forces as custodians of Ataturk’s secular legacy, cheered the coup. Its leaders are now at last facing trial; opinions are belatedly shifting amid gruesome revelations of the army’s misdeeds. A recent poll suggests that, for the first time, the presidency has supplanted the army as the country’s most popular institution. And a report by the Platform for Soldiers’ Rights, an advocacy group, detailing abuse of conscripts, has dealt a further blow. Some 934 soldiers are said to have committed suicide over the past decade, surpassing the number killed while fighting the PKK. Were the conscripts killed by their superiors? Their parents want to know.