CAIRO — When bread shortages swept Egypt in 2008, the government didn't rely on the free market or its own warehouses, but turned instead to army bakeries to churn out millions of flat loaves to calm the angry masses. A few months later, as fire raced through the upper house of parliament, soldiers helped put out the flames.

The nation's military has been an enduring force for stability and the quiet power behind President Hosni Mubarak's 30-year rule. That tanks and smiling soldiers are now spread across the capital and accepted by anti-government protests is a testament to the army's unique role in keeping the public trust while remaining loyal to one of its own, the 82-year-old president.

The military's allegiances will be tested in coming days in negotiations to form a transitional government as Mubarak, whom officials are looking to nudge aside with dignity, fades as a dominating presence. But opposition groups demanding a wider voice, most notably the Muslim Brotherhood, have for years been regarded as national security threats by Defense Minister Field Marshal Mohamed Hussein Tantawi.

Egypt's history of crushing dissent indicates that the tolerance the military is showing toward protesters may not hold if it senses that its interests are in jeopardy. U.S. diplomatic cables released by WikiLeaks, which predate by several years the current crisis, suggest that the Egyptian military may be too rigid and unwilling to adapt to a new political era and the prospect that for the first time since 1956 the nation's president will not come from its ranks.

"Tantawi said one of the military's roles is to protect constitutional legitimacy and internal stability, signaling his willingness to use the military to control the Muslim Brotherhood in the run-up to . . . elections," says a 2008 cable the U.S. Embassy in Cairo sent to the White House.

The documents say Mubarak and Tantawi, described as "aged and change resistant," are focused on "maintaining their status quo through the end of their time. They simply do not have the energy, inclination or world view to do anything differently."

The kindred relationship between Mubarak and his chief military commander did not extend to the president's son, Gamal, who until the current crisis was expected by many to succeed his father. Gamal has no military background and the army's leadership criticized his economic reforms as benefiting the wealthy while creating "social instability" among the poor and middle class.

The cables suggest that the military, which receives more than $1.2 billion in annual U.S. aid, would intervene in politics if it believed the political order or its own interests were threatened. One document quotes an unidentified Egyptian analyst as saying he had been told by army officers "that the military does not support Gamal and if Mubarak died in office, the military would seize power rather than allow Gamal to succeed his father."

Since that memo was written three years ago, Egypt has been dramatically altered by 13 days of widespread demonstrations to overthrow Hosni Mubarak. The political calculations and the police state that held the ruling party together are being redrawn. Most of the party leadership, including Gamal, resigned Saturday, a further sign that the younger Mubarak has been forced to give up any ambitions to rule Egypt.

Protesters have joked and sung with soldiers in Tahrir Square, a sign that the army remains popular in a crisis that is all but destroying the credibility of other public institutions, especially the police. The army has vowed not to fire on protesters and has appeared to at least tacitly support the demonstrations.

What is unclear, though, is how long the military can navigate the middle ground between a rattled government and a restive people.

"It is obvious that Mubarak has the army's full loyalty. However, this is not unconditional and whether the army is willing to take the people's side or not will only depend on the anti-Mubarak demonstrators' ability to maintain pressure," said retired Gen. Abdel Rahman Abdel Halim.

He added: "If their presence in large numbers in Tahrir goes on for a longer period, only then would some army generals get fed up and be willing to strike a deal with the U.S. to oust him as the only solution to the conflict."

But many protesters worry the military would take a different tack. Khaled Mounir, an engineer, said: "The generals will interfere if Mubarak is forced out. Then they will ensure that his replacement is someone they approve of or another army man."

The military's mythology has been imprinted on the nation since 1952 when a group of officers led by Gamal Abdel Nasser staged a bloodless coup to overthrow the monarchy. Nasser was elected president in 1956, followed by Anwar Sadat in 1970. Mubarak, a former air force officer, became president upon Sadat's assassination by Islamic militants in 1981.

Egypt's army and other Arab forces were humiliated by Israel during the 1967 Middle East War. Pride was restored when the military performed better during the 1973 war with Israel. Since then, murals of battlefields, army museums and glimpses of old fighter jets line the road from the Cairo airport to the city center.

In a country of widespread poverty and limited opportunity, the military once offered recruits from provinces and cities a chance at escape and respect in officers' clubs that have sprung up over the decades on bases once occupied by the British. Hundreds of retired generals, colonels and other officers run army-owned corporations for construction, gasoline, hotels and other industries in a sprawling commercial universe.

"The army is the most important and strongest player in Egypt's political equation," said Ammar Ali Hassan, an analyst and former military officer. "The U.S. knows that the army has the power and the U.S. will not stand and watch what's happening in Egypt forever. ... That's why the U.S is doing its best to make a move through the military to end the current crisis."

On Friday, Tantawi inspected troops on Tahrir Square and met with protesters. Such a scene would have been fantasy two weeks ago. It shows how fluid and unpredictable Egypt has become. But it remains unclear how tolerant the military will be to new voices — religious and secular — and the divisive changes likely to erupt on the political landscape.