Turkey's parliament has finally elected former Islamist Abdullah Gul as state president, following an election won by the ruling Islamist-rooted Justice and Development Party, or AKP.
Secularists held huge rallies in May - before the AKP's election triumph
Why was this parliament vote so controversial?
After months of political tension the AK Party again nominated Abdullah Gul, Turkey's foreign minister whose wife wears the Muslim headscarf. His candidacy sparked political turmoil in April, because secularist parties suspected the AKP of harbouring a secret Islamist agenda. When they boycotted the vote Turkish Prime Minister Recep Tayyip Erdogan decided to call a snap election to resolve the crisis.
The presidency is traditionally seen as a bastion of the secular state established by modern Turkey's founder, Mustafa Kemal Ataturk. The president is the armed forces' chief, with influence over senior appointments - and in the powerful military establishment, Islamist activities and headscarf-wearing wives are not tolerated.
Why did it take several attempts for Abdullah Gul to get elected?
In the previous two rounds of voting - on 20 and 24 August - he did not get the necessary two-thirds in parliament. But in the third round a simple majority was enough - 276 votes. He actually got 339 votes in the 550-seat chamber, where the AKP has a commanding majority.
The parliamentary vote before the general election was a debacle after secularist parties decided to boycott it, leading the constitutional court to annul it because insufficient MPs were present in the chamber. But this time only the secularist Republican People's Party (CHP) repeated the boycott.
Hayrunisa Gul is set to be the first headscarf-wearing First Lady
The opposition right-wing Nationalist Action Party (MHP) and pro-Kurdish centre-left DSP fielded candidates - Sebahattin Cakmakoglu and Huseyin Tayfun Icli - who got 70 and 13 votes, respectively.
Could Abdullah Gul still be thwarted by street protests or a military coup?
Such a scenario is unlikely. Secularist politicians did manage to mobilise millions of Turks to demonstrate against the AKP in April-May. But the AKP went on to win decisively in the 22 July general election - so it can argue persuasively that it has a strong mandate from the electorate.
The vote for the AKP also indicated that many Turks did not believe suggestions that the party had a secret Islamist agenda. It also indicated a rejection of the armed forces' so-called "e-coup" - a warning from the military before the election that it would not hesitate to defend the secular system.
The Turkish military regards itself as the guardian of Turkey's secular constitution. To this end, it kicked governments out of power in 1997, 1980, 1971 and 1960.
But in the last few years its political powers have been whittled down. The national security council now contains more elected civilians, and the civilian government can audit military accounts. Last year, military courts lost the power to try civilians.
However, the European Commission noted in a report last November that the armed forces still exercise "significant political influence".
The big pro-AKP vote is widely seen as a signal that Turkish voters will not accept any military move that undermines democracy. A coup would also seriously jeopardise Turkey's bid to join the European Union.
Yet the military has made it clear that it will keep the AKP under close scrutiny. On 27 August - the eve of the third-round vote in parliament - Turkey's military commander Gen Yasar Buyukanit warned that "centres of evil" were trying to undermine the state.
Is this a power struggle between Islamists and secularists?
Not exactly. The AKP is descended from the banned Welfare Party, which saw Turkey as part of the Islamic world and opposed Turkish membership of the EU. But the AKP leaders have changed their position completely, enacting liberalising reforms to bring Turkey closer to EU membership than ever before. These include sweeping reforms to the judiciary.
The AKP has been in power since 2002 and has made a point of not provoking secularists. For example, it has avoided relaxing Turkey's laws banning the wearing of the headscarf in state institutions.
Mr Gul, a founder-member of the AKP, has pledged his commitment to Turkey's secular institutions, which embody a strict separation of religion and state. He says he wants to represent all Turks. He has lived in Saudi Arabia and Britain and has developed good relations with many foreign leaders.