(c) 2013, Bloomberg News.

(c) 2013, Bloomberg News.

The following editorial appears on Bloomberg View:

The hope that Turkey might provide a model for modernizing Muslim countries combining Islam, democracy and market economics is being tested. A bitter quarrel between Prime Minister Recep Tayyip Erdogan and his former allies continues to escalate. Financial markets are running scared, punishing the country's stocks and currency. The fight doesn't just threaten Erdogan's government; it also calls into question vital Turkish institutions, including the rule of law.

In this struggle among Turkey's religious conservatives, there's no sense in outsiders choosing sides though they can remind Erdogan and his opponents of what is at stake. If Turkey is to move past this new outbreak of strife, the government and its critics alike must take up the unfinished business of strengthening the country's still-fragile civic foundations. As yet, there seems little appetite for that in either camp.

The heaviest responsibility lies with Erdogan himself, who on Sunday accused his opponents of "treason" that had cost the economy billions of dollars. Since he swept to a third successive election victory in 2011, ominously declaring the advent of his "master period," he's moved away from the pragmatism that made him strong. Now challenged by followers of Fetullah Gulen, an Islamic teacher, his response has been more desperate than masterful.

Corruption investigations implicating ministers in Erdogan's government provoked this new crisis. It's widely believed that many prosecutors and investigators are Gulenists, and that their charges are politically motivated. Erdogan repeated on Sunday that a "parallel state" was trying to force him from power, and in a way he's right. So far the probes have forced him to accept the resignations of three Cabinet ministers and remove a fourth in a broader cabinet reshuffle. Now prosecutors are trying to launch a new inquiry into an organization run by Erdogan's family. After resigning on Christmas Day, former minister for the environment and urban works Erdogan Bayraktar said that Erdogan personally approved deals under investigation and should quit.

Erdogan is much to blame for his predicament. He inherited institutions that had been tools of the army-backed secularist establishment that had previously ruled Turkey. Instead of reforming them, he filled them with then-allies from the Gulen movement. He made the courts, police and special prosecutors tools of his own and they duly crushed the military, sometimes using fabricated evidence.

Once the military was tamed, Erdogan and Gulen fell out. The same prosecutors turned on the government, and Erdogan has now turned on them. In the past two weeks he's purged about 500 senior police officers believed to be sympathetic to Gulen; new prosecutors have been inserted into the corruption investigations; and a lead prosecutor in the cases was removed after complaining about interference. Erdogan's new Cabinet is packed with loyalists, and it seems designed mainly to take on Gulen.

Erdogan has called it a second "independence struggle," invoking the real war that Mustafa Kemal Ataturk fought to prevent Greece, France, Britain and Russia from carving up the heart of the collapsed Ottoman Empire in the early 1920s. He's even hinted that the U.S. ambassador in Ankara is behind an international conspiracy to unseat him. Nonsense of this sort threatens Turkey's most important security relationship and who will it convince in any case? The investigators may be politically motivated, but the evidence they've collected is reaching the public and the wrongdoing they seem to have uncovered can't be so easily dismissed.

Erdogan needs to make clear that the corruption cases will be properly investigated and answered. To make that credible, he should admit to his own role in politicizing the courts and judiciary, then embark on genuine reform. He should also call early parliamentary elections. His Justice and Development Party would most likely return to power, though with a smaller majority that might oblige him to share power. He should declare his willingness to do that.

The United States and European Union should mostly stand aside, lest they feed Erdogan's conspiracy theories. But the EU would do well to recognize that the 2009 decision to block negotiations for Turkey's entry into the union, especially in the area of justice, freedom and security, was a mistake. That error should be put right, encouraging Turkey to meet the EU's judicial and law-enforcement standards, which would help build confidence in its institutions.

But the country's fate lies mainly with Erdogan. For the most part, he served Turkey well during his first two terms. He can serve it well again and retrieve its stability and growing prosperity by bringing his disastrous "master period" to an end.