CAIRO -- For most of his year in power, President Mohamed Morsi and the Muslim Brotherhood thought they had tamed Egypt's military, forcing out top generals and reaching a deal with their successors that protected the armed forces from civilian oversight.
That deal collapsed this week.
With tanks and soldiers in the streets and around the presidential palace, the military's top officer, Gen. Abdul-Fattah el-Sisi, did not even utter Mr. Morsi's name as he announced that the president had been deposed and the Constitution suspended.
And suddenly, Mr. Morsi, like his immediate predecessor, Hosni Mubarak, discovered the enduring fact that the military looks out for itself above all else. It is not ideological, but is intensely politicized.
"Egypt's military leaders are not ideologically committed to one thing or the other; they believe in their place in the political order," said Steven A. Cook, a Middle East expert at the Council on Foreign Relations. "They are willing to make a deal with virtually anyone, and this one didn't work out, clearly."
While justifying its intervention in politics as serving the will of the people, the military has never been a force for democracy. It has one primary objective, analysts said: preserving national stability and its untouchable realm of privilege within the Egyptian state.
But with millions in the street opposing the president, and the Brotherhood consistently trying to consolidate its authority, the military decided that time was up on the Morsi presidency.
"We are disciplined, and we have the weapons," one ranking officer said Wednesday, speaking on the condition of anonymity because he was not authorized to comment. "That's what's on the market right now. Do you see any other solid institution on the scene?"
The face of that military was General Sisi, a rakish officer, his chest full of medals, a beret pulled tight over his forehead, as he grasped a lectern with both hands and addressed his nation, insisting that the goal was to restore national unity. He played down the military's dominance as he installed a caretaker leader.
But his words of reconciliation and healing could not alter the cold reality of the moment.
The military, for the second time in two and a half years, was ousting the nation's civilian leader -- but this time, that leader had been elected, freely and fairly. The removal underlined the armed forces' status as Egypt's most powerful institution since the coup six decades ago that toppled King Farouq and led to the rise of Gamal Abdel Nasser.
"There was hope," General Sisi said in his televised address, "that there would be a national consensus to set a road map for the future and provide reasons for trust, assurance and stability for this nation, in a way that fulfills its ambition and aspiration."
Egypt has the largest standing military in the Arab world, estimated at 450,000 troops. Most are conscripts and low-ranking officers who have little opportunity for advancement.
For decades, however, its tens of thousands of elite officers have jealously guarded their privileged station. They live as a class apart, with their own social clubs, hotels, hospitals, parks and other benefits financed by the state.
Many have also grown wealthy through government contracts and business deals facilitated by their positions. It is, in some respects, a hereditary Brahmin caste, in which sons follow their fathers' careers and they all live inside a closed social circle.
"It is a tightly knit group," said Robert Springborg, a professor at the Naval Postgraduate School in Monterey, Calif., and an expert on the Egyptian military. "They tend to think alike and they are a force to be reckoned with because, besides the Brotherhood, they are the only really cohesive institution in the country."
For six decades before the revolution in 2011, military men ruled Egypt. For most of his nearly three decades in power, Mr. Mubarak, a former air force commander, largely let the military operate as it liked. But after 18 days of a mass uprising in 2011 against his rule, the military decided the deal was off. Stability was threatened. Mr. Mubarak's long-serving defense minister, Field Marshal Mohamed Hussein Tantawi, who had been known as "Mubarak's poodle," ousted and jailed him.
For more than a year, the military ran Egypt -- and learned a lesson that apparently guides its decisions now. Running the government left its officers vulnerable to public outrage over economic, social and political problems. The period was marred by economic decline and street unrest.
The most common protest chant became "Down, down with military rule!"
Michael Wahid Hanna, a researcher at the Century Foundation, said the military wanted nothing more than to be able to go back to its barracks.
"They don't like being front-line actors, and they don't like being police," he said. "Mostly they just want things to settle down."
Although many in the military distrusted Mr. Morsi's Islamist background -- the Brotherhood had been outlawed before the revolution -- they welcomed his inauguration in June 2012 as an exit from the accountability of governing. Mr. Morsi also granted two key demands: squashing the possibility of postrevolutionary prosecutions of military officials for Mubarak-era crimes and passing a Constitution that excused the military budget from parliamentary oversight.
That, plus the perception that Brotherhood members were at least competent and disciplined managers, appeared to give the military confidence that the Islamist group would be a worthy partner. That view changed as internal crises mounted. The economy continued to plunge, and fuel shortages and power cuts caused anger in the streets.
Mr. Morsi also took a number of steps that the military saw as jeopardizing national security. He spoke at a mass rally where Muslim clerics called for jihad in Syria, raising fears of a new generation of radicalized Egyptians coming home from a foreign war.
When he addressed the nation on Wednesday night, General Sisi said the military had reached out to the presidency for months to try to defuse the crisis but had been repeatedly rebuffed. In appointing a little-known judge as interim leader, the military did not make clear how much authority he would have or whether it would run the country behind the scenes.
But analysts said the opposition was naïve in cheering the military's return to power as a step in the postrevolutionary transition to democracy.
"The liberals and the revolutionaries are too quick to hop into bed with the military -- it is not their friend," said Mr. Cook of the Council on Foreign Relations. "The most important thing from the military's perspective is preserving its place as the locus of power and influence in the system."
Mayy El Sheikh contributed reporting.
This article originally appeared in The New York Times.