Coffee shop customers watched President Mohamed Morsi give a televised speech from Cairo University after his inauguration. CAIRO - Mohamed Morsi of the Muslim Brotherhood was formally sworn in on Saturday as the first democratically elected president of Egypt, signaling a new stage in an ever murkier struggle to define the future of the nation after six decades of military-backed autocracy. As Egypt's first civilian president and the first Islamist elected to lead an Arab state, Mr. Morsi has vowed to fulfill the goals of the Egyptian revolution by building the institutions of democracy on a foundation of Islamic principles. Mr. Morsi, against his wishes, took the oath before a court of Mubarak-appointed judges; he had vowed to swear in before the democratically elected and Islamist-led Parliament, but the generals dissolved it on the eve of his election under the pretext of a ruling from the very same court. Then, in inviting the new president to take the oath, Judge Sultan specifically cited the authority of the interim Constitution issued by military decree on June 17, which transferred most of the powers of the president's office to the ruling generals - a document Mr. Morsi, the Brotherhood and tens of thousands of their supporters occupying Tahrir Square have called illegitimate. Mr. Morsi pre-empted the generals" planned inauguration by reciting his oath a day earlier in a televised speech before a rapturous crowd that filled Tahrir Square, the heart of the revolution. And after his formal inauguration on Saturday, Mr. Morsi proceeded to recite the same oath a third time, before the lawmakers of the dissolved Parliament, the ruling generals and foreign ambassadors in an auditorium at Cairo University. Field Marshal Mohamed Hussein Tantawi, who had acted as head of state until Saturday and will maintain the title of defense minister by military fiat, sat at the center of the front row. Alongside him sat Saad el-Katatni, the Brotherhood leader who was speaker of Parliament. With them in places of honor were two Egyptian Nobel Prize winners: Ahmed Zewail, a chemist, and Mohamed ElBaradei, a former United Nations diplomat who became a guiding voice of the movement for democracy here. "Egypt will not go backward," Mr. Morsi said. In the new Egypt, the president will be an employee, a servant to the people. But he also continued his subtle efforts to wield the prestige of his new post against the ruling generals. Without acknowledging the dissolution of the legislature, he praised it as triumph of democracy. "The people projected their will and exercised their power with election of Parliament in free and fair elections that were representative of society," he said. He lavished tributes and gratitude on the ruling Supreme Council of the Armed Forces for its role in safeguarding the transition. But he also pointedly called for the military to return to the barracks and borders. "The elected institutions will come back to play their role and the Egyptian armed forces, Egypt's great army, will go back to its main job to maintain and safeguard the borders," he said, pledging to keep the armed forces "strong and solid, to work with the other institutions of the government, within the Constitution and within the law."