Foreign Minister Abdullah Gul failed to win the Turkish presidency in a second round of voting in parliament on Friday, but is expected to clinch the post next week, hoping to end months of political tensions.
Gul, a highly respected diplomat who helped secure European Union-accession talks for Turkey, is distrusted by the military and secular elite because he served as a minister in an Islamist party chased from power in 1997.
Friday's vote was the second of up to four rounds. Gul is expected to be elected in the third session on August 28 when he no longer needs two-thirds of the votes but a simple majority - which the ruling Islamist-rooted AK Party has.
A parliament official announced that Gul had received 337 votes in the 550-seat chamber, confirming what an AK Party deputy had earlier told Reuters before a recount. The result meant several AK Party members did not vote for the minister.
Two opposition candidates also stood. The Nato-member country of 74 million people is predominantly Muslim but is governed by a secular constitution.
The AK Party is accused of seeking to undermine a separation of religion and state dating back to the founding of the republic after the collapse of the Ottoman Empire. The party denies the charges and points to its EU reforms and pro-business record in office.
Turkey's financial markets, troubled by months of political turmoil, were this time focused on volatility in global markets with the election regarded as a foregone conclusion. The lira currency eased to 1.3310 against the dollar on Friday while Istanbul's main share index fell 1.5 percent.
Gul, 56, says he backs secularism but opposition from the secularist elite remains fierce, in part because his wife wears the Muslim headscarf, seen by secularists as a provocative symbol of religion. The scarf is banned in public offices.
Few expect the army, which has ousted four governments since 1960, to intervene directly after its strong public statements earlier this year appeared to backfire and helped secure more votes for the AK Party in the recent parliamentary election. The army is unlikely to sit by quietly if they perceive that secularism is coming under threat, analysts and politicians say.