Cairo, Egypt - Not long ago, former Egyptian President Mohamed Morsi may have thought he had reined in Egypt's powerful military.
He had managed to sack the top brass and reached an agreement with the army to keep their replacements out of politics.
Morsi also helped push through a controversial constitution that codified some of the military's prerogatives - such as shielding their budget from parliamentary oversight - perks which had previously been an unofficial agreement with the presidency.
In return, the army, which governed Egypt for 16 months after Hosni Mubarak's fall, went back to its barracks and left politics to the civilians.
However, with the overthrowing of the president on Wednesday, analysts point out that this "uncomfortable" balance between the government and the army was only possible as long as a one condition was met - stability.
Michael Hanna, a researcher at the Century Foundation, said that while the officer corps may lack ideological attachments, it has entrenched interests, which were threatened when hundreds of thousands of people took to the streets on Sunday demanding Morsi's ousting.
The army was forced to act, he said, because it feared the possibility of widespread violence and state collapse.
"Their modus vivendi was possible, uncomfortable but possible, in the sense that the military doesn't have strict ideological attachments," Hanna said.
"But the threshold for them is stability."
The army's interest in stability stems in part from a desire to preserve its privileged place in society. It has had a hand in politics for decades, ever since a group of officers deposed King Farouq in 1952.
Every Egyptian president since then has been a military officer - until Morsi came into power in 2011.
Members of the military have their own clubs and vacation with their families in military-owned hotels; the army also controls a wide range of businesses, which account for up to 40 percent of the country's economic output.
Morsi showed few signs of wanting to challenge the military's prerogatives. In addition to keeping the army budget hidden, he had done nothing to address widespread human rights abuses during the period of military rule; the contents of a 700-page fact-finding report on the subject still have not been released to the public.
However, despite these apparent overtures, he spurned the army's calls for national dialogue after he issued a controversial decree in November shielding his decisions from judicial review.
"Everyone feels knifed in the back by the Brotherhood, but the military is in a position to do something about it," said Robert Springborg, a professor at the Naval Postgraduate School in the US state of California who has written extensively on the Egyptian army.
Military chief General Abdel Fattah al-Sisi "felt personally insulted by Morsi... there is a certain amount of score-settling going on".
Sisi alluded to this in his speech on Wednesday night, blaming the now-former president, whose whereabouts are not publicly known, for the failure of reconciliation talks.
"Hope was pinned on national reconciliation to lay down a road map for the future," Sisi said in his televised address.
"However, the speech of the president [on Tuesday] night, before the end of the 48-hour grace period, neither met nor conformed to the demands of the masses."
Army officials declined to be interviewed for this article.
According to analysts, the generals are likely to operate behind the scenes this time, uniting around a presidential candidate and cutting their own deals with him.
The modus vivendi with Morsi was further weakened when he started to weigh in on foreign policy.
Egypt's General Intelligence Service has always handled relations with the Palestinian group Hamas, but Morsi and his Brotherhood have long cultivated their own ties with the group. He won widespread praise after Egypt negotiated a ceasefire to end the eight-day war between Hamas and Israel last November.
It has been Morsi's missteps more than his successes that raised tensions with the army. There was an awkward moment last month, when Morsi organised a meeting to discuss a controversial new dam being built on the Nile in Ethiopia. The project would divert water from Egypt's main source.
At the conference, which was aired live on state television, attendees proposed invading Ethiopia and sending weapons to rebel groups there.
Last month, Morsi also attended a conference on Syria at which speakers called for "holy war" against President Bashar al-Assad. The remarks, which urged Egyptians to fight abroad, may have been the final tipping point for the army, according to analysts.
"They crossed the red line on security. They kept playing politics with national security in ways that made the military profoundly uncomfortable," Springborg said.
"They were using foreign policy to build domestic support, which is always a dangerous game... the army felt double-crossed."
Follow Gregg Carlstrom on Twitter: @glcarlstrom
Source: Al Jazeera