CAIRO -- When Egypt's first elected president, Mohamed Morsi, promoted Gen. Abdul-Fattah el-Sisi to defense minister nearly a year ago, sweeping away an aging cadre of generals, many saw it as a triumph for the Islamist president, and for a fledgling democracy.
Mr. Morsi had seized back broad powers from the old guard, and General Sisi, known to be pious, seemed to have a close relationship with the new president, even sending Mr. Morsi a laudatory telegram. "The men of the armed forces assert to your excellency their absolute loyalty to Egypt and its people, standing behind its leadership as guardians of the patriotic responsibility," it read.
Mr. Morsi is now a prisoner of the military, deposed by General Sisi on July 3 after mass protests against the president's rule. And the telegenic general, who has cast himself as protector of Egypt's security and its very identity, is riding a wave of muscular nationalism and pro-military sentiment that has led his adoring fans to liken him to former President Gamal Abdel Nasser.
The conflicting perceptions of General Sisi -- seasoned officer reluctantly answering a call to serve, ambitious man with a "sense of destiny," as one person who knows him put it -- leave much of Egypt wondering whether he intends to return the country to civilian rule, as he has repeatedly promised, or to capitalize on public support for him by seeking power, formally or informally, for himself.
The American-trained general has been confronted with weeks of continuous sit-ins and protests by the now-deposed Muslim Brotherhood, overseeing the two worst episodes of killings of demonstrators by the security services since the 2011 uprising. The authorities have ordered an end to two sit-ins in Cairo, raising the specter of a broadening crackdown on the Brotherhood.
The Brotherhood had counted on winning broader support against General Sisi after Mr. Morsi's ouster, and then after the death of scores of protesters. While the Islamists have maintained their vigils and marches around the country, General Sisi has so far managed to stir up enough support among opponents of the Brotherhood to generate backing for an even tougher crackdown.
"The army stands neutral before all factions," General Sisi told Egyptians in a recent speech, saying that coming elections would be supervised "by the whole world." But in the same speech, he asked millions of people to take to the streets on his behalf, to fight "violence and terrorism," a reference to his Islamist opponents.
"Shoulder the responsibility with the army and the police," he said.
When Mr. Morsi picked General Sisi as defense minister, the general was a rising star, having served as the chief of military intelligence while drawing notice among defense officials in the United States. In 2005, he trained at the United States Army War College in Pennsylvania, where he seemed especially drawn to a course dealing with civilian-military relations, according to his adviser at the college, Col. Stephen J. Gerras.
At the war college, General Sisi wrestled with the question of "Democracy in the Middle East," the title of a paper he wrote. More searching than dogmatic, the 17-page paper seemed to be heavily influenced by the war in Iraq and was critical of American attempts to impose democracy in the region.
He criticized the practices of autocratic governments without ever singling out Egypt, saying they rigged elections and controlled the news media using "outright intimidation." Religious leaders "who step beyond their bounds in government matters are often sent to prison without trial."
The Arab world needed to create its own version of democracy, he said, mentioning a moderate religious foundation, education and poverty alleviation as critical elements. Islamist groups needed to be included in the process, "including radical ones," he said.
After President Hosni Mubarak was toppled, General Sisi served on the army council that ran the country, where he was said to have run the negotiations with the Brotherhood, the country's most powerful political force. He kept a low profile, but his name surfaced at least once in the headlines, when he acknowledged to Amnesty International that the military had subjected female protesters to "virginity tests" -- and said they had been performed to protect soldiers from rape allegations.
"The whole idea was absurd," said Salil Shetty, the secretary general of Amnesty International, who met with General Sisi. The general said the practice would stop, but took the "paternalistic" view that Egyptians would expect the army to protect soldiers from such allegations, rather than the victims, Mr. Shetty said.
After he became defense minister, General Sisi worked to improve morale in his military, which was still reeling from criticism of its stewardship of Egypt after the fall of Mr. Mubarak in 2011. He raised salaries and pensions, and doubled the size of apartments for officers. The general, who showed up to work at 5 a.m., visited soldiers nearly every day, jogging with them in shows of vigor and attention that the military publicized.
An officer who had been wary of General Sisi at first, fearing he was too close to Mr. Morsi, said the general's "daring" had changed his views. "He gave me the best training," the officer said. "He adopted a new approach toward my administrative problems, and he showed me financial appreciation. What more do I want?"
At first, the defense minister "kept a very, very low profile," said Hossam Bahgat, a human-rights activist in Egypt. "His appearances were at graduation ceremonies. There were almost no comments on politics or public affairs. There seems to have been a very studied approach to his public profile.
"Then, of course, things changed," he said.
In November, Mr. Morsi declared his authority above the courts, prompting fears that he was becoming autocratic. In December, the president's Islamist allies rammed through a new Constitution, ignoring the complaints about the process and the charter from non-Islamists, further polarizing the country. Mr. Morsi struggled to win cooperation from Egypt's extensive state bureaucracy, as his enemies began to circle.
At the same time, General Sisi, showing a knack for politics, made new friends.
When police officers went on strike, General Sisi held public dinners with senior police officials and sent emissaries to negotiate labor issues. When food poisoning sickened hundreds of students at Al-Azhar University, the prestigious center of Sunni Muslim thinking, Egyptians protested against the Brotherhood, which had tense relations with Al-Azhar's leaders.
General Sisi stepped in, sending ovens, deep fryers and other kitchen equipment in a convoy of military trucks, to show his solidarity with Al-Azhar.
Mr. Morsi's colleagues accuse General Sisi of working to undermine the president, for instance, by stepping in after Mr. Morsi seized new powers in November, and publicly inviting political leaders to a dialogue. One aide accused him of a more serious betrayal, saying the general had met with activists who were trying to depose the president. The general's politicking -- with Al-Azhar, and political leaders -- was not just a friendly gesture, Mr. Morsi's allies say. When General Sisi announced the military intervention that toppled the president, the leaders the general had courted were sitting at his side.
In his speech last week, General Sisi categorically rejected the allegations, saying he had never "conspired" and had repeatedly warned Mr. Morsi to change course. He and other leaders in the military, Egypt's most powerful institution and a virtual state within a state, were increasingly alarmed by Mr. Morsi's behavior, diplomats and analysts said. The anger started with a slight in October, at an anniversary celebration of the 1973 war with Israel. General Sisi found himself sitting near Tarek al-Zomor, a guest of the president who had been convicted of playing a role in the 1981 assassination of Anwar el-Sadat.
"Instead of sitting with officers who had shed their blood, he was forced to sit with the killer of General Sadat," said a colleague of General Sisi.
The military's discomfort grew as the economy plummeted and, in particular, as a dispute with Ethiopia over access to water in the Nile grew more serious. One diplomat said General Sisi had started to come under increasing pressure from mid-ranking officers to act.
The generals were also disturbed by investigations into their own wrongdoing. As one of his first acts, Mr. Morsi created a fact-finding commission to look into the deaths of protesters during the revolution against Mr. Mubarak, up until June 30, 2012, the last day of military rule. The report included victim testimony alleging torture by members of General Sisi's military intelligence branch. Mr. Morsi refused to publicize the report, and no investigations into the military resulted from it.
Analysts and people who know the general said they believed he was serious about returning the military to its barracks. The second-tier leadership he represented when he became defense minister "didn't just reject the old guard," said Michael Wahid Hanna, who studies Egyptian politics and the military at the Century Foundation. "They also didn't appreciate the incessant and direct interference in politics."
The general's speech about terrorism raised doubts, though. "I'm very surprised he's choosing to be front and center," Mr. Hanna said.
Mr. Morsi's fall was in some respects the latest phase in the continuing battle for supremacy between the military and the Brotherhood, marked by frequent deal-making and, now, open conflict. In the end, Mr. Morsi was outmaneuvered, by a general who appealed to notions of Egyptian identity that he had accused the Islamists of betraying.
General Sisi said the Brotherhood had started to turn a conservative nation against religion. But the general, and the army he commanded, would ensure that "Egypt remains Egypt," he said.
Mayy El Sheikh contributed reporting from Cairo, and Eric Schmitt from Washington.
This article originally appeared in The New York Times.