Turkey's Constitutional Court has rejected a demand to outlaw the country's ruling Justice and Development (AK) party on charges of undermining Turkey's secular system.
But judges have decided to cut the AK party's state funding by half, in what they called a "warning."
The decision was announced in Ankara after three days of deliberations by the president of the Constitutional Court, Hasim Kilic But it was a close call.
Kilic detailed how the top court's 11 judges cast their votes. Seven votes were needed for an outright ban. And the AK party survived by the barest of margins.
"Six of the judges voted for banning the party. Out of five judges, four of them voted in favor of not giving government aid to the party, and one voted against the ban. Considering that six judges were in favor of the ban and four were in favor of cutting financial aid, when we consider all these together, the court has decided to cut aid for the year for this political party in half," Kilic said.
Kilic called the aid cut a "serious warning" and he advised the party to "get the message it should get." He said the judges who supported the financial sanctions decided the AK party had become a "focal point" of antisecular activities, as the country's chief prosecutor had argued.
The verdict ended months of political uncertainty which had hit Turkey's financial markets on fears that the democratically elected party would be closed down, halting economic and political reforms.
The AK party has its roots in political Islam, but its leaders deny it has an Islamist agenda. It enjoys broad popular support and won 47 percent of the vote in general elections a year ago.
But the party's opponents -- who include powerful members of the military establishment and see themselves as guardians of Turkey's secularism -- argued that the ruling party was trying to establish an Islamic state.
Chief Prosecutor Abdurrahman Yalcinkaya had sought to close the party and ban 71 of its leading figures, including Prime Minister Recep Tayyip Erdogan and President Abdullah Gul, from belonging to any political party for five years.
A ruling to close the AK party would have triggered the fall of the government and plunged the country into crisis. There were fears it would have provoked unrest and had a major economic and foreign policy impact, as well.
European Commission chief Jose Manuel Barroso warned back in April that a decision to ban the part it would have a "major impact" on the way Turkey was seen by the EU. Now that has been averted and many in Turkey will be breathing sigh of relief.
The speaker of parliament, Koksal Toptan, welcomed the judges' decision, saying they had "lifted the bar of democracy" in his country. But as the court made clear, the suspicion and animosity that divide the Turkish political establishment have not been erased.