Hosni Mubarak ruled Egypt for almost 30 years until he was swept from power in a wave of mass protests in February 2011.
Few expected that the little-known vice-president who was elevated to the presidency in the wake of Anwar Sadat's 1981 assassination would hold on to the country's top job for so long.
Sadat was assassinated by Islamist militants at a military parade in Cairo, and Mr Mubarak was lucky to escape the shots as he sat next to him.
Since then, he has survived at least six assassination attempts - the narrowest escape shortly after his arrival in the Ethiopian capital, Addis Ababa, in 1995 to attend an African summit, when his limousine came under attack.
Besides his knack for dodging bullets, the former air force commander also managed to keep a hold on power by positioning himself as a trusted Western ally and fighting off a powerful opposition movement at home.
It all came to an end in a televised address on 1 February 2011, following mass protests in Cairo and other cities. Mr Mubarak announced he had decided not to stand for re-election later that year.
Protests continued and on 10 February he appeared on state television to say he was handing over powers to his vice-president, but would remain as president.
The following day Vice-President Omar Suleiman made a terse announcement saying Mr Mubarak was stepping down and the military's supreme council would run the country.
'I have a good conscience'
By late May 2011, judicial officials announced that Mr Mubarak, along with his two sons - Alaa and Gamal - would stand trial over the deaths of anti-government protesters.
So began a protracted series of court appearances - with the former president often been seen in the dock in an upright stretcher wearing his trademark sunglasses.
He has steadfastly argued his innocence - telling a retrial in August that that he was approaching the end of his life "with a good conscience".
On 2 June 2012 he was found guilty of complicity in the murder of some of the demonstrators who took part in the wave of protests that began on 25 January 2011. Along with his former Interior Minister, Habib al-Adly, he was sentenced to life imprisonment for his crimes.
In January 2013 a court upheld an appeal against Mr Mubarak's and Mr al-Adly's convictions and granted retrials. Mr Mubarak and his sons were also ordered to be retried on corruption charges for which they were originally acquitted.
Mr Mubarak was released from prison in August that year but placed under house arrest before being transferred to a military hospital.
In May 2014, Mubarak was found guilty of embezzlement, and sentenced to three years in prison. Alaa and Gamal were sentenced to four years each. The convictions were overturned in January 2015, but a retrial reinstated the same sentences.
An appeals court upheld the sentences a year later, but Alaa and Gamal were freed because of time already served.
In November 2014, Mr Mubarak was finally acquitted in a retrial of conspiring to kill protesters during the 2011 uprising. At the same time, he was also acquitted of corruption charges involving gas exports to Israel.
In March 2017 Egypt's top appeals court upheld Mr Mubarak's acquittal and he went free, for the first time in six years.
A strict personal life
Born in 1928 in a small village in Menofya province near Cairo, Muhammad Hosni Sayyid Mubarak insisted on keeping his private life out of the public domain while president.
Married to a half-British graduate of the American University in Cairo, Suzanne Mubarak, he was known to lead a strict life with a fixed daily schedule that began at 0600.
Never a smoker or a drinker, he built himself a reputation as a fit man who led a healthy life.
In his younger days, close associates often complained of the president's schedule, which began with a workout in the gym or a game of squash.
He was sworn in as president on 14 October 1981, eight days after the Sadat assassination.
Despite having little popular appeal or international profile at the time, the burly military man used his sponsorship of the issue behind Sadat's killing - peace with Israel - to build up his reputation as an international statesman.
Egypt's quasi-military leader
In effect, Mr Mubarak ruled as a quasi-military leader when he took power.
For his entire period in office, he kept the country under emergency law, giving the state sweeping powers of arrest and curbing basic freedoms.
The government argued the draconian regime was necessary to combat Islamist terrorism, which came in waves during the decades of Mr Mubarak's rule - often targeting Egypt's lucrative tourism sector.
He presided over a period of domestic stability and economic development that meant most of his fellow countrymen accepted his monopolisation of power.
But towards the end of his tenure in power, Mr Mubarak felt for the first time the pressure to encourage democracy, both from within Egypt, and from his most powerful ally, the United States.
Many supporters of reform doubted the veteran ruler's sincerity when he said he was all for opening up the political process.
Ahead of his declaration that he would not to stand again for the presidency, the US had heaped pressure on him to stand aside, calling for an "orderly transition" of power to a more democratic system.
Mr Mubarak won three elections unopposed since 1981, but for his fourth contest in 2005 - after a firm push from the US - he changed the system to allow rival candidates.
Critics said the election was heavily weighted in favour of Mr Mubarak and the National Democratic Party (NDP). They accused the Egyptian leader of presiding over a sustained campaign of suppressing
'History will judge me'
The length of his time in power, along with his age and possible successors, had all been sensitive subjects in Egypt until the mass protests allowed the Egyptian people to find a voice.
People around Mr Mubarak said his health and vigour belied his age - although a couple of health scares served as a reminder of his advancing years.
Rumours about the president's health gathered pace when he travelled to Germany in March 2010 for gall bladder surgery. They flared every time he missed a key gathering or disappeared from the media spotlight for any conspicuous length of time.
However much Egyptian officials tried to deny them, they kept circulating, with reports in the Israeli and pan-Arab media.
The days of mass protests in Egyptian cities prompted Mr Mubarak to finally name a vice-president. On 29 January 2011, intelligence chief Omar Suleiman was elevated to the role in what was seen as an attempt by Mr Mubarak to bolster his support in the military.
Two weeks later Mr Mubarak's three-decade rule was over, and in March he was under arrest.
In the past, Mr Mubarak had said he would continue to serve Egypt until his last breath.
In his speech on 1 February 2011, he said: "This dear nation... is where I lived, I fought for it and defended its soil, sovereignty and interests. On its soil I will die. History will judge me like it did others."