Addressing members of his ruling Justice and Development Party, Erdogan hailed the court's decision. "Democracy wins," he said to vigorous applause. "Political and economic stability win."

The court, however, halved state funding of the party for one year, and its chief jurist said most members found credible evidence that party leaders had undermined secularism.

Court chairman Hasim Kilic said the ruling party should interpret the outcome as a "serious warning" and "take the necessary lessons from this."

The case threatened to unseat Erdogan, along with scores of lawmakers from his party. Justice and Development won 47 percent of the vote in parliamentary elections last year, in part because of the country's economic growth and because of the party's determination to win Turkish membership in the European Union.

Six of the court's 11 judges voted to outlaw the party, falling one vote short of the seven needed in this case. Four other judges agreed with the prosecutor's contention that the party had undermined Turkey's constitutionally mandated secularism but decided that cutting its funding was an adequate sanction. Kilic favored neither option.

Party supporters labeled the case an attempted "judicial coup" and accused secular leaders of resorting to judicial maneuvers to attempt to seize political power they were unable to attain at the ballot box.

Turkish political parties have been banned by the judiciary in the past, but this case marked the first time a popular ruling party faced such a prospect. The decision averted an abrupt change of guard at a time when Turkey is grappling with domestic terrorism and seeking to bolster its case for inclusion in the E.U.

But the underlying political tension that led to the standoff remains. The country's ruling party, whose leaders are observant Muslims, and the secular establishment, which includes opposition parties, the military and the judiciary, are beset by deep mutual bitterness and suspicion.

They are at odds over a question that has divided Turks for years: What role, if any, should Islam play in the affairs of a predominantly Muslim democratic state whose constitution regards secularism as sacred?

"There is no consensus as to what secularism is and how it should be maintained," said Bulent Aliriza, the director of the Turkey Project at the Center for Strategic and International Studies in Washington. "What you have is leaders who are not secular who are trying to change the rigorous aspects of secularism. The ruling party has accepted the continuation of secularism. What it is trying to do is adjust it to take it to the wishes of the electorate."

Abdurrahman Yalcinkaya, the country's top prosecutor, filed a lengthy complaint against the party this spring, alleging that its leaders were steering the country toward conservative Islamic values in violation of the country's secular principles.