After 84 years as a secret society struggling in the prisons and shadows of monarchs and dictators, the Brotherhood is now closer than ever to its stated goal of building an Islamist democracy in Egypt. “In my dreams, I wanted this to happen, but it is unbelievable,” said Hudaida Hassan, a 20-year-old from Menoufiya who was rejoicing in the square.

Brotherhood leaders emphasized that their struggle was far from over. They promised to continue the sit-in and fight on in the courts and the streets to reinstate Parliament. In his short first statement as president-elect, Mr. Morsi vowed to take the oath of office before the reseated Parliament, and not the Supreme Constitutional Court, as the generals had decreed.

Field Marshal Mohamed Hussein Tantawi, the chairman of the military council, congratulated Mr. Morsi. The official presidential guard, which once protected Mr. Mubarak, arrived at Mr. Morsi’s home to take up their new role. Until 16 months ago, their appearance at the home of a Brotherhood leader could only mean a trip to one of Mr. Mubarak’s jails. Mr. Morsi himself was jailed for a time in 2008 and again during the revolt last year against Mr. Mubarak.

State television, long a wellspring of propaganda against the Brotherhood, broadcast Mr. Morsi’s victory speech on Sunday. In it, he pledged repeatedly to be “a president for all Egyptians.” He quoted the first Muslim caliph to describe his authority in Islamic terms, but he also extended a hand to Egypt’s large Coptic Christian minority, many of whom remain dubious of him. “We as Egyptians, Muslims and Christians, are preachers of civilization and building; so we were, and so we will remain, God willing,” he said. “We will face together the strife and conspiracies that target our national unity.

“We are all equal in rights, and we all have duties towards this homeland,” he added. “But for me, I have no rights, I have only duties.” He also repeated his pledge to uphold all international agreements, an apparent reference to Egypt’s peace treaty with Israel.

The Coptic Church formally congratulated him, calling the election a victory for democracy.

Fulfilling a campaign promise, Mr. Morsi resigned on Sunday from the Brotherhood and its political arm, the Freedom and Justice Party. He is expected to appoint a prime minister and cabinet in the next few days. He has promised that the prime minister and an advisory council would come from outside the Brotherhood as part of a unity government based on a rebuilt alliance with liberals and other secular activists.