Recep Tayyip Erdogan shows that democracy and moderate Islam can be a good mix.

THE CAUSES of Middle East democracy and moderate Islam should get a badly needed boost from last weekend's parliamentary elections in Turkey. The ruling Justice and Development Party, or AK Party, which is led by the religious, liberal and pro-Western Prime Minister Recep Tayyip Erdogan, won a convincing victory, dealing a rebuff not only to leftist and nationalist opponents but also to the Turkish military. The militantly secular army effectively forced the election by threatening to intervene in the political system in April; the election results showed that Turks do not share the army's fear of the AK Party and that they rejected its meddling.

Turkey is different from its Arab neighbors, including Iraq. But the success of the AK Party both in government and at the polls is demonstrating that political parties grounded in Islam can not only thrive within a democratic political system but also help to strengthen it. Mr. Erdogan, like many Turks from the country's sprawling interior, is a devout Muslim, but he has made no move during five years in office to Islamicize Turkish government or curb the rights of secular Turks. On the contrary, he has pushed through liberalizing reforms, including greater rights for women; presided over an economic boom driven by foreign trade and investment; and pressed for Turkish entry into the European Union.

With parliament due to elect a new president this year, Mr. Erdogan characteristically sought to avoid antagonizing his opponents and the military by refraining from seeking the office himself. Instead, he nominated his capable foreign minister, Abdullah Gul, another pro-Western moderate. The army nevertheless responded by posting a threatening message on its Web site; this "e-coup," as Turks called it, was followed by a parliamentary impasse over the election.

Though vindicated by the resulting election, Mr. Erdogan can best follow up on his success with more restraint. He has already suggested that he will look for a compromise candidate for the presidency. But he will also have to hold back the hardliners in the military and new parliament who will be pressing for a Turkish military intervention in northern Iraq. Turks need still more economic reforms, foreign investment and integration with Europe, something that can happen only if the country's leaders avoid succumbing either to nationalist or Islamist agendas. If Mr. Erdogan can steer that tricky course, he will benefit not only his country but also the troubled region around it.