Hosni Mubarak, Egypt's president for almost 30 years who stepped down after a popular revolution in 2011, has died. He was 91.

Mubarak served as Egypt's fourth president starting in 1981 until his removal in what became known as the Arab Spring revolution.

Egypt will bury its former president on Wednesday after a military funeral in the capital Cairo. Egypt's top military officials are expected to attend the funeral in an eastern suburb of Cairo, but it was not clear if President Abdel Fattah el-Sisi would do so.

Mubarak's coffin will be air lifted from the mosque where the funeral will be held to the burial grounds, state television reported.

More:

Mubarak was jailed for years after the 2001 uprising, but was freed in 2017 after being acquitted of most charges. The acquittal stunned many Egyptians, thousands of whom poured into central Cairo to show their anger against the court.

The Arab Spring protests convulsed regimes across the Middle East.

State television said Mubarak died at a Cairo hospital where he had undergone an unspecified surgery. The report said he had health complications but offered no other details. One of his sons, Alaa, announced over the weekend the former president was in an intensive care after undergoing surgery.

Egypt's presidency said in a statement that it mourned Mubarak's death as a "military leader and war hero" and has offered its condolences to his family.

Complicated legacy

Throughout his rule, Mubarak was a stalwart United States ally, a bulwark against armed groups, and guardian of Egypt's peace with Israel.

But to the tens of thousands of young Egyptians who rallied for 18 days of unprecedented street protests in Cairo's central Tahrir Square and elsewhere in 2011, Mubarak was a relic, a latter-day pharaoh.

Al Jazeera's Jamal al-Shayyal, reporting from Tunis, Tunisia, where the Arab Spring originated, said it was unclear what exactly killed the former leader.

"What we're looking at now is a statesman who was so controversial in the past three-four decades of Egypt's history. It was under his rule that Egypt became more corrupt. It was under his rule that the infrastructure in the country reached a demise," he said.

"For sure his passing is something that will remind people of the situation in Egypt as well as the political legacy that he left behind, which is one that has allowed for the current military regime to continue in its ruling."

National hero

Mubarak was born in a rural village in the Nile Delta on May 4, 1928. He left behind a complicated legacy as his rule was partly characterised by corruption, police brutality, political repression, and entrenched economic problems.

The former president had long maintained his innocence and said history would judge him a patriot who served his country selflessly.

He joined the Egyptian air force in 1949, graduating as a pilot the following year. He rose through the ranks to become the commander-in-chief of the Egyptian air force in 1972.

Mubarak became a national hero the following year with reports that the Egyptian air force dealt a substantial blow to Israeli forces in Sinai during the Yom Kippur War.

Mubarak was vice president on October 14, 1981, when his mentor, President Anwar Sadat, was assassinated by fighters while reviewing a military parade.

Seated next to Sadat, Mubarak escaped with a minor hand injury as gunmen sprayed the reviewing stand with bullets. Eight days later, the brawny former air force commander was sworn in as president, promising continuity and order.

His harsh stance on security enabled him to maintain the peace treaty with Israel. Under his rule, Egypt remained a key US ally in the region - receiving $1.3bn a year in US military aid by 2011.

Crony capitalism

Mubarak had been sentenced to life in prison in 2012 for conspiring to murder 239 demonstrators during the 18-day revolt.

An appeals court ordered a retrial and the case against Mubarak and his senior officials was dropped. He was finally acquitted in 2017.

He was however convicted in 2015 along with his two sons of diverting public funds and using the money to upgrade family properties. They were sentenced to three years in jail.

Since his arrest in April 2011, Mubarak spent the nearly six years in jail in hospitals. Following his release, he was taken to an apartment in Cairo's Heliopolis district.

Many Egyptians who lived through Mubarak's time in power view it as "a period of autocracy and crony capitalism". His overthrow led to Egypt's first free election, which brought in President Mohamed Morsi.

Morsi lasted only a year in office after mass protests in 2013 led to his overthrow by then defence chief General Abdel Fattah el-Sisi, who is now president.

Mubarak-era figures, meanwhile, are gradually being cleared of charges, and laws limiting political freedoms have raised fears among activists that the old regime is back.

Over the years, Mubarak tinkered with reform but shunned significant change, presenting himself as Egypt's sole protection against militancy and sectarian division. The US tried pushing him harder for reforms, but succeeded only in alienating him. Fearful of losing its alliance with the most powerful Arab country, Washington backed off.

But the failure to fulfil repeated promises of change steadily deepened public despair, and those seeking a democratic future were dismayed to see Mubarak making apparent moves to set up a dynastic succession in the shape of his businessman son, Gamal.

Mubarak is survived by his wife, Suzanne, and his sons, Gamal and Alaa.