ANKARA, Turkey - A devout Muslim with a background in political Islam won the Turkish presidency on Tuesday, in a major triumph for the Islamic-rooted government after months of confrontation with the secular establishment.

Foreign Minister Abdullah Gul received a majority of 339 votes in a parliamentary ballot and took the oath of office, pledging impartiality and loyalty to Turkey's historic separation of religion and politics. Commanders from the fiercely secular military were conspicuously absent -- a decision many saw as a symbolic protest against the decision to elect a president to a post traditionally held by a secular figure.

"Secularism -- one of the main principles of our republic -- is a precondition for social peace as much as it is a liberating model for different lifestyles," Gul said. "As long as I am in office, I will embrace all our citizens without any bias. I will preserve my impartiality with the greatest of care."

Gul's victory took place a day after the military, which has ousted four governments since 1960, issued a stern warning about the threat to secularism. Gul's initial bid for president was blocked over fears that he planned to dilute secular traditions.

"Our nation has been watching the behavior of those separatists who can't embrace Turkey's unitary nature, and centers of evil that systematically try to corrode the secular nature of the Turkish Republic," Gen. Yasar Buyukanit, chief of the military, said in a note on the military's Web site Monday.

Turkey's president has the power to veto legislation, and Gul has failed to allay secularist fears that he would sign into law any legislation passed by the government of Prime Minister Recep Tayyip Erdogan -- a close ally -- without concern.

Also, his wife wears an Islamic-style head scarf -- which is banned in government offices and schools. Islamic attire has been restricted in Turkey since the country's first president, Mustafa Kemal Ataturk, ushered in secularism and Western-style reforms in the 1930s.

Gul, 56, failed to win the presidency in two rounds of voting last week because the ruling Justice and Development party lacked the two-thirds majority in Parliament needed for him to secure the post. But the party -- which holds 341 of the 550 seats -- had a far easier hurdle on Tuesday, when only a simple majority was required.

In Washington, State Department spokesman Tom Casey said the United States welcomed "this exercise in Turkish democracy. We think it continues the course of democratic development in that country."

Erdogan said he planned to submit his new Cabinet to Gul for his approval on Wednesday. Erdogan had presented his list earlier this month to outgoing President Ahmet Necdet Sezer, who said the new president should approve it.

"I hope (Gul's presidency) is beneficial to the country, the people and the republic," Erdogan said. "God willing, together, shoulder to shoulder, we will carry Turkey forward."

In Gul's hometown of Kayseri, in Turkey's conservative heartland, hundreds gathered at a main square to celebrate his victory, private NTV television reported.

Secularist Turks staged mass rallies and the military threatened to intervene when Erdogan nominated Gul for president in the spring.

Gul insisted that he be re-nominated for president earlier this month, arguing that his party's victory in the elections gave him a strong mandate to run. He rejected calls from secularist parties to step aside in favor of a non-Islamist, compromise candidate.

"A person who has defied the (secular) republic, who has said he finds it to be wrong, is about to move to the top of the state. This is a contradiction," said Deniz Baykal, leader of the secular opposition. His party boycotted the vote on Tuesday and has said it would not take part in some state occasions, including presidential ceremonies.

As foreign minister, Gul -- who speaks English and Arabic -- has cultivated an image as a moderate politician.

In a recent meeting with foreign journalists, Gul said he would make use of his experiences as foreign minister to boost Turkey's European Union bid and make the Turkish presidency more active on the international scene.

"Turkey will be more active; Turkey will be contributing more to world issues," he said.

The EU said the vote "represents a considerable achievement for Turkey and the Turkish people,"

In a statement, European Commission President Jose Manuel Barroso said he hoped the government "will be able to resume work ... to give fresh, immediate and positive impetus" to EU entry talks.