In a reversal of fortunes unthinkable a year and a half ago, an Islamist jailed by Hosni Mubarak has succeeded him as president of the biggest Arab nation in a victory at the ballot box which has historic consequences for Egypt and the Middle East.
The Muslim Brotherhood's Mohamed Morsi will not enjoy the extent of modern, pharaonic powers exercised by Mubarak: those have been curtailed by a military establishment which will decide just how much he will be able to do in government.
Still, the US-trained engineer's victory in the country's first free presidential election breaks a tradition of domination by men from the armed forces, which have provided every Egyptian leader since the overthrow of the monarchy 60 years ago, and installs in office a group that drew on 84 years of grassroots activism to catapult Morsi into the presidency.
He has promised a moderate, modern Islamist agenda to steer Egypt into a new democratic era where autocracy will be replaced by transparent government that respects human rights and revives the fortunes of a powerful Arab state long in decline. Morsi is promising an "Egyptian renaissance with an Islamic foundation".
Yet the stocky, bespectacled 60-year old, appears something of an accidental president: he was only flung into the race at the last moment by the disqualification on a technicality of Khairat al-Shater, by far the group's preferred choice.
With a stiff and formal style, Morsi, who has a doctorate from the University of Southern California, cast himself as a reluctant late comer to the race, who cited religious fear of judgment day as one of his reasons for running. He struggled to shake off his label as the Brotherhood's "spare tire."
Questions remain over the extent to which Morsi will operate independently of other Brotherhood leaders once in office: his manifesto was drawn up by the group's policymakers. The role Shater might play has been one focus of debate in Egypt.
"I will treat everyone equally and be a servant of the Egyptian people," Morsi said at his campaign headquarters in Cairo shortly after polling ended, a week before his victory was confirmed by the Mubarak-era body overseeing the vote.
But many Egyptians, not least the Christian minority, remain suspicious of Morsi and even more so of the group he represents. Anti-Brotherhood sentiment, fuelled by both a hostile media and some of the group's policies, has soared in recent weeks.
Ahmed Shafik, the former general he defeated, won nearly as many votes as Morsi, signaling that Egypt is a nation that is anything but united around the idea of Brotherhood rule. Morsi won a little less than a quarter of the first-round vote in May.
That a man who served as Mubarak's last prime minister was so close to victory has been seen as one sign of failure by the Brotherhood - which has described itself as the victim of a vicious campaign orchestrated by its enemies.
At first, Morsi pitched himself as a conservative Islamist - the only one in the field, he said. He repeatedly promised to implement Islamic law in speeches peppered with references to God, the Prophet Mohammad and the Koran.
"It was for the sake of the Islamic sharia that men were ... thrown into prison. Their blood and existence rests on our shoulders now," Morsi said in one of his early campaign rallies.
'Jerusalem is in our hearts.' Morsi prays (Photo: AFP)
Though not one of those jailed for years, he was held on more than one occasion by Mubarak's feared state security men.
But he has seldom spelled out what precisely his call to implement sharia, or Islamic law, would mean for Egypt, where piety runs deep and the constitution already defines the principles of the sharia as the main source of legislation.
Morsi has said Brotherhood rule would not mean that Egypt will be a theocracy, adding that there is little difference between the phrase "the principles of the sharia" - the term found in the current constitution - and the sharia itself.
Pushed by one TV interviewer to clarify what Islamist rule might mean for bikinis on Red Sea beaches - and so for Egypt's vital tourist industry - Morsi did not give a clear answer.
He described such issues as "very marginal, very superficial and affecting a very limited number of places", adding that sector specialists must be consulted on all draft laws.
It was typical of the vagueness that has fuelled concerns among those Egyptians whose fears were also exacerbated by other elements of the Morsi campaign, including his early efforts to court the ultraorthodox Salafi Islamist movement.
In a gesture to Gama'a al-Islamiya, one such group, Morsi pledged to work for the release of Sheikh Omar Abdel-Rahman, a militant preacher imprisoned in the United States for planning the 1993 World Trade Center bombing.
Another cleric, the independent Safwat el-Hegazi, added a radical flavor to Morsi's early campaign, taking to the stage at his events to call for a Muslim super-state across the Middle East with Jerusalem as its capital - a direct challenge to Israel with whom Mubarak maintained a 33-year-old peace treaty.
Morsi subsequently distanced himself from such statements, but not before the Shafik campaign had used them to great effect to paint the Brotherhood's man as a dangerous radical.
Asked about Hegazy's remarks, Morsi later spoke of European Union-style integration for the Arab world and an Arab common market. "Jerusalem is in our hearts and vision," he said. "But Cairo is Egypt's capital."
As he readied himself for the run-off against Shafik, Morsi switched to a more inclusive message and portrayed himself as defender of the "January 25 revolution" that toppled Mubarak - an uprising initially led not by the wary Brotherhood but by mainly secular, liberal groups among Egypt's urban youth.
The Brotherhood has long been at the heart of the movement for democratic reform in Egypt, but he was a hard sell to many of those youth activists, who said his group was slow to join the anti-Mubarak uprising and who subsequently accused the Brotherhood of cozying up to the generals who then took over.
Morsi won few open endorsements from politicians and parties beyond the various Islamist factions, though the "April 6 movement" - one of the protest groups that ignited the anti-Mubarak revolt - was a notable exception.
"We face a decisive moment in our history, we must halt the farce of the former regime," Morsi said in one of his last television interviews before the run-off. "We face a new era and we cannot allow the return of the former regime."
Morsi worked to address some of the criticisms faced by his group. In the last week of his campaign, he put in writing his promises of an inclusive administration, to protect media freedoms and those of minorities, including Christians whose fear of the Islamists drove many of them to vote for Shafik.
He also sought to reassure the generals about his group's intentions. In a June 14 interview, he said the Brotherhood would seek agreement with the military over the next defense minister. The army, he said, would also remain "protector of the interior" for up to two years while the Interior Ministry - a largely unreformed vestige of Mubarak's rule - was restructured.
In any case, the army enacted a court order that same day to dissolve the Brotherhood-led parliament and, as polling ended, issued a decree taking legislative power for itself, among measures that will sharply constrain the presidency.
Morsi travelled across the country, promoting the Brotherhood's "renaissance project" - an 80-page manifesto based on what it terms its "centrist understanding" of Islam.
The son of a peasant farmer, Morsi has spoken of a simple childhood in a village in the Nile Delta province of Sharqia, recalling how his mother taught him prayer and the Koran. He obtained his doctorate from the University of Southern California in 1982 after earlier studying at Cairo University.
Following his studies in the United States, he returned to Egypt in 1985. Two of his five children hold US citizenship.
Head of the Freedom and Justice Party, which the Brotherhood established last year to promote its aims in the new party political system, Morsi has been described as an apparatchik.
His daughter is married to the son of another Brotherhood leader and he has described his wife, who wears a long, cape-like headscarf, as a Brotherhood activist.
The Brotherhood's "renaissance" program sketches out the group's vision on everything from fighting inflation to remaking ties with the United States as a partnership of equals. It envisions deeper ties with Turkey - a Muslim state which Brotherhood leaders often cite as a model of success.
On Israel, Morsi's views reflect those of the Brotherhood. He has called for a review of Cairo's 1979 peace treaty with its Jewish neighbor, saying Egypt's neighbor has not respected the accord. But the group has said it will not renege on the deal.
Morsi has cited fear of judgment day as one reason for seeking the top office. He said: "We are worried that God will ask us, on the day of reckoning: 'What did you do when you saw that the nation was in need of sacrifice and effort?'"