Hosni Mubarak, who has died aged 91, was a stubborn and uninspiring dictator who clung to power as president of Egypt for three decades. He was periodically challenged by would-be rivals and survived at least six assassination attempts until he finally stepped down at the dramatic height of the Arab spring protests in February 2011, subsequently facing trial and imprisonment as the consequences of his country’s faltering revolution played out.

Mubarak hung on until the bitter end, sending his thuggish supporters on to the streets of Cairo and beyond to confront people who had overcome their fear with mass protests that took Egypt to the brink of civil war. Until he went, after 18 tense and heady days, the capital’s Tahrir Square became a symbol of popular hope and empowerment.

The demand “Irhal!” (“Leave!”), a pithy summary of unprecedented mass mobilisation, echoed across the Middle East before Mubarak complied and retired to a secluded villa on the Red Sea.

Back in 1981, when he became president, few Egyptians, and fewer foreign observers, had imagined he would ever rule the Arab world’s most populous country. He had been a hard-working and low-profile vice-president who operated mostly behind the scenes. All that changed in a hail of gunfire on 6 October that year when President Anwar Sadat was assassinated by a group of renegade Islamist army officers during a military parade in Cairo. Mubarak was injured. Eight days later he was sworn in as president. He was then 53 years old.

Facebook Twitter Pinterest Hosni Mubarak in court for his trial in Cairo in 2011. Photograph: Reuters

In the shocked aftermath of Sadat’s assassination and the brief but bloody uprising which followed it, it seemed unlikely that the Mubarak government would survive for long. But he went on to preside over a regime as stable – some would say static or even moribund – as any in the region. Even more remarkably, he guided Egypt back into the mainstream of Arab affairs, from which it had been ignominiously ejected for making peace with Israel in 1979.

In the final years of his reign, Sadat had become ever more megalomaniac and authoritarian. He was infuriated by dissidence and, in the last weeks of his life, ordered mass arrests of intellectuals of every shade, and both Muslim and Christian clerics.

Mubarak showed no mercy to Sadat’s assassins, who were hanged, but he quickly released most of those whom Sadat had peremptorily imprisoned. In his first speech he made the obligatory promise to crack down on corruption and even spoke of democratic reforms. It all seemed too good to be true, and it was.

Egypt, a country of desperate poverty and venality, needed much, much more than a good administrator. In the 1990s, its population grew at the dizzying rate of a million every eight months, and by 2010 it had topped 84 million. A survey showed that 70,000 Egyptians had net assets of more than US$5m each, while at least half of their fellow citizens lived in squalor on the equivalent of $1.50 a day.

Mubarak’s fumbling attempts at economic reform had little impact on the poor. Nor did he curb the corruption endemic in public life. There was much muttering about the success in business of his two sons, Alaa and Gamal, and the wealthy cliques surrounding them, as well as persistent talk that Gamal was being groomed for the succession. Egypt’s first lady was initially an asset: Suzanne Thabet, the daughter of an Egyptian doctor and a Welsh nurse, who married Mubarak in 1959, eschewed open involvement in state affairs and devoted herself to social work, although she still came to symbolise the sense of entitlement and dynastic ambitions of the first family.

Since the fall of the monarchy in 1952 and the establishment of the Egyptian republic the following year, the country had had just four presidents by 2011: the figurehead coup leader Mohammed Naguib, Gamal Abdel Nasser, Sadat and Mubarak. All ruled only with the consent of the armed services. In Mubarak’s later years, though, the armed forces’ power – especially their once unassailable economic position – was undermined by privatisation and the rise of competing elites. In the end, the supreme council of the armed forces moved to oust Mubarak. Still, offered the opportunity to leave Egypt, he refused, saying he would die in his homeland.

Facebook Twitter Pinterest Hosni Mubarak and Bill Clinton in Washington in 1999. Photograph: Joyce Naltchayan/EPA

In public, Mubarak presented an impassive manner. In private, he was a good deal more demonstrative and, on occasion, hot-tempered. Had he shown more flair in domestic affairs, or devoted to them the same energy he gave to his international manoeuvres, he might have given some substance to the delusions of grandeur he shared with Nasser and Sadat. These were shattered when he was brought to court in Cairo in August 2011, accused of corruption, embezzlement, and the unlawful killing of protesters during the uprising. He was the first Arab leader to be tried in his own country.

Born in the village of Kafr al-Musaliha in the Nile Delta, Mubarak was the son of a minor official in the ministry of justice. His rural accent was later much mocked by sophisticated Cairenes. (He was also called, behind his back, “la vache qui rit” – “the laughing cow” – on account of his perceived resemblance to the little red cow on the box of the eponymous French processed cheese.) But Mubarak’s bumpkin speech and fixed smile masked a sharp intellect and a driving ambition.

Like his predecessors, his path to prominence was a military one. When he graduated from the Air Force Academy, King Farouk was on the throne and the Egyptian air force still flew Spitfires. During the Free Officers Movement revolt of 1952, which toppled the monarchy and eventually brought the charismatic Nasser to power, Mubarak was a fighter pilot.

Throughout the Nasser era, the trauma of the Suez war of 1956 and the calamitous defeat in the six-day war with Israel in 1967, Mubarak moved steadily up the promotion ladder. His progress accelerated after the war, when he moved from the command of the air force academy to become the chief of staff, with the rank of air vice-marshal.

In the early 70s, Mubarak was air force commander and played a central role in planning Egypt’s attempt to take back the Sinai Peninsula, lost to Israel in 1967. Militarily, the October 1973 war – conducted jointly with Syria – was an abject failure, but the bravery of the Egyptian forces and especially their stunning early success in crossing the Suez Canal, buoyed national morale and boosted the popularity of Sadat’s presidency.

Facebook Twitter Pinterest Hosni Mubarak, left, with Anwar Sadat in 1981. Photograph: Bill Foley/AP

By 1974 Mubarak was a full air marshal, much admired by his military peers. In April the following year he was picked by Sadat – who came from the same region of Lower Egypt – to be his vice-president. It was an unexpected choice: Mubarak had no experience of politics and no popular base. But he had the all-important endorsement of the military high command. He was unquestionably loyal and hardworking, and his dogged, down-to-earth manner complemented Sadat’s flamboyant style.

It was a momentous time to enter Egyptian politics. Sadat, for whom the 1973 war had redeemed his own and his nation’s pride, decided to win back Sinai by a startlingly different means: a peace agreement with Israel. Throughout the convoluted Camp David negotiations which led to the historic peace treaty of 1979, Mubarak was a stalwart lieutenant and key player. It was not a popular role, for the Egyptian public was stunned by the new strategy, and the rest of the Arab world was shrill with fury and cries of treachery.

Mubarak, when his time came to lead, inherited a deeply unpopular regime, propped up by the hated secret police. But he had two important advantages: there was no serious challenger for the presidency and, unlike his impulsive predecessor, he was steady and cautious by nature.

But by the 90s, there were serious challenges to his rule, with a surge of Islamist power adding to the perennial misery of the Egyptian masses. The Muslim Brotherhood, which was founded in Egypt, had been influential for decades and, although technically illegal, it still managed to form a coherent parliamentary opposition, with its members sitting as independents. But the Brotherhood was too sedate for young bloods inspired by the Palestinian intifada, the first Gulf war and the rising power of al-Qaida and other extremist groups.

The Gamaa al-Islamiya (Muslim Group), an out-and-out revolutionary organisation, first erupted into Egyptian life in the 80s, with the corrupt and widely detested police as its main target. Western visitors were attacked, with a devastating effect on the tourist trade. The government’s response was harsh and violent. Soon there were horrific reports of gross human rights abuses, of hostage-taking, rape and torture.

Meanwhile, Mubarak’s vague talk of moves towards democracy also proved to be a cruel mirage. Having succeeded to the presidency without a popular mandate, he went on to award himself three successive election “victories”. The technique was simple: he was nominated in parliament by his own National Democratic party and then ratified as president in referendums in which he was unopposed.

In 2005, Mubarak announced multiparty parliamentary elections and a multicandidate presidential poll. The outcome of both was a mix of farce and tragedy, with massive rigging and intimidation. For the parliamentary elections, the president relaxed restrictions on the Muslim Brotherhood. It remained proscribed as an organisation, but members were allowed to stand as independents under the slogan “Islam is the solution”.

In spite of harassment and intimidation, the Islamists captured some 40% of the votes and 20% of the seats in parliament. It was a scapegoat opposition – visible but marginalised – and easy to blame.

No such chances were taken in the presidential vote. Mubarak’s men, alarmed by the impact being made by his leading rival, the liberal democrat Ayman Nour, had Nour arrested on blatantly bogus charges of forgery. Nour was duly pronounced guilty and imprisoned. He also lost his parliamentary seat.

In the subsequent announcement of the skewed election, Mubarak was credited with 88.6% of the vote and Nour with 7.3%. But even the presidential toadies could not conceal the abjectly low turnout of 22.9%. In spite of protests by human rights groups, most western governments remained silent, while Washington swallowed the official Cairo line that its principal Arab ally had moved towards democratic reform.

Aid money continued to pour in, on the formula that for every three dollars handed to Israel, Egypt would get two. Much of the tens of billions went on warplanes, helicopters, tanks and other military hardware, which kept the top brass happy. Many retired generals became provincial governors.

Mubarak was more imaginative in matters of foreign policy. From the outset, he opted to stick by the peace deal with Israel, which resulted in the full return of the Sinai by 1982. In truth, he had little option, because of the massive subventions of US aid.

Still, it was never more than a cold peace, based as much on mutual incomprehension as on pragmatism. Israel constantly chivvied Egypt into signing up more Arab countries for a regional settlement, but could not, or would not, understand that the continued occupation of the Palestinian territories made that impossible.

Egyptians, too, had difficulty in understanding the peace. The constant stream of Jewish settlers into the occupied West Bank, the collective punishments of Palestinians, the bloody intrusions into Lebanon – all these infuriated the Egyptian public and establishment. The partially free press mirrored the popular mood by regularly featuring crude racist abuse of Israelis.

Mubarak, craving a pivotal role in a wider peace process, worked tirelessly to have his country readmitted to the Arab League. He succeeded: by the end of the 80s the League was once again meeting in Cairo. But to Mubarak’s frustration, other Arab leaders stuck doggedly to their own national and regional strategies, while both Israel and the US remained wary of their Egyptian ally.

The disturbances of January and February 2011 in Cairo and other cities were followed nervously in Jerusalem and Washington. The US was primarily interested in ensuring continuing regional stability, and was anxious that Egypt might slip into an Islamist system – a fear stoked by Iran’s support for the opposition. However much Washington condemned violence and repression, it could not bring itself to call publicly on Mubarak to step down. Israel had even more reason to dread a radical regime on its doorstep.

Mubarak and his aides cared little about Israeli fears but they were terrified of losing their American ally and the largesse it brought. Mubarak’s regime, in essence, rested on three pillars: public acquiescence, if not support; US and wider western tolerance; and military backing. Early on in the unrest, the army command announced that it would not use force against the Egyptian people. But that was different from saying that Mubarak had lost the support of the military, still less that the army was preparing to intervene.

Following the Tahrir Square protests and his decision to step down, in May 2011 Mubarak was ordered to stand trial. In June 2012 he was sentenced to life imprisonment shortly before the election victory of the Muslim Brotherhood’s Mohamed Morsi. Mubarak’s name was removed from a Cairo Metro station.

Morsi was overthrown in 2013 by Abdel-Fattah al-Sisi, another military man. Dogged by ill-health, including stomach cancer – wheeled in and out of court on a hospital bed – Mubarak was acquitted on the killing charges and quietly released from military hospital custody in March 2017. In 2018 his sons were arrested for alleged stock market manipulation but acquitted just days before his death.

For those who had worked to topple him, Mubarak’s freedom marked a grim moment. Other Egyptians reacted with resignation after the years of turmoil, violence and continuing repression that followed his fall.

He is survived by his wife and sons.

• Mohammed Hosni Sayyid Mubarak, politician, born 4 May 1928; died 25 February 2020

• Derek Brown died in 2011