Kemal Atatürk's banner hangs along side Turkish flags from the facade of a building in Eceabat, Dardanelles, Turkey. Atatürk was a revolutionary Ottoman and Turkish army officer who founded Republic of Turkey as a modern, westernized and secular state — the principles known as Kemalism. Image by Adam Jones. Turkey, 2011.

In this year of upheaval in the Middle East, a barely mentioned story may mark one of the most important developments in the region.

In July, the Turkish army's top four generals resigned in what critics say was a misbegotten attempt to trigger a national crisis. The generals, led by Chief of Staff Isik Kosaner, seemed to be hoping that their dramatic departure would topple the country's moderate Islamist government and restore the military's primacy in Turkish politics.

The story is what didn't happen next. The generals' resignation briefly roiled the waters of Turkish politics, but failed to overturn the civilian government. Prime Minister Recep Tayyip Erdogan quickly reasserted control over the military brass, replacing Kosaner with a general of his own choosing. He then convened a meeting of the Senior Military Council, a high-level assembly usually co-chaired by the prime minister and the chief of staff. This time, however, Erdogan sat alone at the head of the table -- sending a clear signal that the civilians were now in charge.

The generals took a reckless gamble with the country's stability, but fortunately for the Middle East's largest and most successful democracy, they lost their bet. Instead of the expected crisis, the Turkish nation quietly bid farewell to 88 years of Kemalism -- the founding ideal that put Turkey on the path of modernization and secularism -- and the notion that the generals always know best.

While vivid scenes of the Arab Spring were becoming YouTube staples across the world, Turkey's ability to overcome this crisis in civil-military relations carries important implications for the entire region. The parallels are striking and the lessons instructive for Egypt, in particular, especially after the Muslim Brotherhood's victory in the first round of Egypt's parliamentary elections.

Both Egypt and Turkey have long histories of domination by their military establishments, which in both cases have been the beneficiaries of generous U.S. support. Since the founding of the modern Turkish republic in 1923, the army has staged four coups, and up until 1989 all but one of Turkey's presidents had come from a military background. In Egypt, the military has been in continuous control since 1952, when Gamal Abdel Nasser led a coup against the monarchy.

When the crowds in Cairo's Tahrir Square demanded the ouster of Hosni Mubarak, himself a former Air Force commander, it was the senior Egyptian military command that told him it was time to go -- and then quietly seized power for itself. The so-called Supreme Council of the Armed Forces, headed by Field Marshal Mohamed Hussein Tantawi, promised to step aside once a new civilian leadership had established itself, but now seems intent on retaining the privileges it enjoyed during the Mubarak era.

For Turkey, loosening the generals' grip has been a long and fraught process. The civilians only began to gain an upper hand with the rise of Erdogan's Justice and Development Party (AKP) -- an offshoot of a banned, avowedly Islamist party that was nevertheless committed to bringing Turkey into the 21st century. The AKP quickly proved successful at maintaining its pious roots while also being democratic, open to the West, and -- as it would turn out -- surprisingly good at running the economy.

When the AKP won a decisive victory in the 2002 election, Erdogan became prime minister and inherited an economy that had been constantly on the brink of disaster. Inflation was over 70 percent, the economy was posting a negative growth rate, and the banking sector was in the throes of a meltdown. A decade later, Turkey's economy has trebled in size and now ranks 17th in the world. And in the face of a lingering global recession, Turkish gross domestic product (GDP) last year grew by 8.9 percent.

Meanwhile, the only signs of creeping Islamization so feared by the generals were hefty new taxes on alcohol and cigarettes, a low-key crackdown on the country's still-legal red-light districts, and a cordial but cautious opening to the likes of Iran and Hamas.

But the generals remained unhappy. By early 2003, senior military officers and others who belonged to what Turks refer to as the "deep state" -- a term used to describe members of the military and other establishment figures who believed they could act outside the law to protect the status quo -- were allegedly busy plotting a coup. According to Markar Esayan, a journalist for Taraf newspaper, their plan was to create a crisis by bombing mosques, assassinating the Armenian patriarch, and shooting down a Turkish plane and blaming it on Greece -- a 2009 plot, code-named "Sledgehammer."

Since then, dozens of senior military officers and hundreds of others -- journalists, businessmen, and academics linked to the deep state -- have been arrested in a mushrooming prosecution.

The case has fascinated and divided Turkey. And while the prosecution of some suspects seems to carry more than a whiff of political vindictiveness on the part of the AKP, there is growing public support for ending the military's overweening role in politics.

In June's general election, Erdogan's party easily won a third term with nearly 50 percent of the vote, almost doubling the total of Republican People's Party (CHP), its closest rival.

Erdogan's success has not gone unnoticed in the Middle East. On a September state visit to Egypt, the Turkish prime minister received a rock star welcome. This was partially explained by his sharp criticism of Israel's blockade of Gaza and the expansion of Jewish settlements on the West Bank, but mainly it is because Egyptians and other Arabs appreciate that Turkey under Erdogan is both democratic and comfortable in its Islamic identity. The Turkish leader appeals because he is religious, but not a demagogue -- because he is open to the West, but not submissive or servile.

"Erdogan," says Burak Erdiner, a senior official in Turkey's Ministry for EU Affairs, "is the only leader who can go to and pray in the mosque on Friday -- and on Saturday lecture the Muslim Brotherhood on secularism." Which is precisely what Erdogan did during the Cairo visit, telling a television interviewer that he hoped the new regime in Egypt would be secular.

With the Muslim Brotherhood's decisive showing in last week's election, Egypt is at a critical juncture. Whether the Brotherhood heeds Erdogan's advice -- and its generals learn from Turkey's example -- will go a long way toward determining the success or failure of the Arab Spring.