A devout Muslim with a background in political Islam won the presidency on Tuesday - a major triumph for Turkey's 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, Parliament Speaker Koksal Toptan said. Ruling party legislators broke into applause, and thousands gathered in a main square in his hometown of Kayseri, in Turkey's conservative heartland, cheered, danced and waved Turkish flags. A canon fired 41 rounds in celebration. Gul, 56, was sworn into office hours later. Commanders from the fiercely secular military were conspicuously absent - a move regarded by many as a symbolic protest against the decision to elect a president to a post traditionally held by a secular figure. After taking his oath, Gul - who consistently denied he has an Islamist agenda - praised the predominantly Muslim nation's secular system and pledged impartiality. "The Turkish Republic is a democratic, secular, social" state "governed by the rule of law," he said. "I will always be determined and resolved to advocate, without discrimination, each of these principles and to further strengthen them at every opportunity." He said "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's initial bid for president earlier this year was blocked over fears that he planned to dilute Turkey's secular traditions. Although a largely ceremonial post, the president has the power to veto legislation, and secularists feared he would sign into law any legislation passed by the government of Prime Minister Recep Tayyip Erdogan - a close ally - without concern for the separation of religion and politics. 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. When Erdogan nominated Gul, secularists staged mass rallies and the military - which has ousted four government since 1960 - threatened to intervene. Lawmakers opposed to Gul's candidacy boycotted votes on his candidacy, thwarting his election. That prompted Erdogan to call early general elections - which his party dominated. Gul then insisted he be re-nominated for president, arguing that his party's victory in the early general 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. But on the eve of the vote, the military issued a stern warning about the threat to secularism. "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 statement posted to the military's Web site Monday. As foreign minister, Gul - who speaks English and Arabic - has cultivated an image as a moderate politician, acting as an impassioned voice for reforms to promote Turkey's bid to join the European Union. He assured lawmakers he would uphold those values. "As long as I am in office, I will embrace all our citizens without any bias," Gul said. "I will preserve my impartiality with the greatest of care." Two other candidates, Sabahattin Cakmakoglu of a nationalist party, and Tayfun Icli of a small center-left party, got 70 and 13 votes, respectively. "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." One of Gul's first tasks as president will be to approve Erdogan's new Cabinet, which the prime minister will present to him on Wednesday. Erdogan had presented his list earlier this month to Sezer, who said the new president should approve it.