Gamal Mubarak (left) and Alaa Mubarak (right) were arrested alongside their father in 2011

A court in Egypt has ordered the release of the two sons of ousted former President Hosni Mubarak.

The Cairo Criminal Court found the time Alaa and Gamal Mubarak had spent in temporary detention exceeded the legal limit, state-owned Nile News TV said.

The two men, who were arrested after the 2011 uprising, were sentenced alongside their father to three years in prison in May for embezzlement.

They are appealing, but also face trial on the charge of insider trading.

Some of the anger that led to Hosni Mubarak’s overthrow was fuelled by the widespread belief that he and his sons had illegally amassed vast amounts of wealth.

Gamal, 51, was a leading member of the former ruling National Democratic Party and was widely seen as his father’s heir apparent. Alaa, 54, was a leader among the business elite.

The brothers were acquitted of the corruption charge, but last year they were sentenced to four years in prison – and their father to three years – after being found guilty of embezzling millions of dollars of state funds.

Prosecutors accused them of using money meant to pay for renovating and maintaining presidential palaces to upgrade their private residences.

But the convictions were overturned in January by the Court of Cassation, which found that legal procedures had not been followed properly and ordered a retrial.

In May, the three men were convicted at retrial and each sentenced to three years. They were also ordered to pay a fine of 125m Egyptian pounds ($15.9m; £10.4m) and repay the 21m Egyptian pounds ($2.7m; £1.7m) they allegedly embezzled.

Hosni Mubarak is currently residing at a military hospital in the southern Cairo suburb of Maadi. It is not clear when the ailing 87 year old will be released.

Charges of conspiring in the killing of hundreds of protesters during the uprising that ended his rule in 2011 were dropped in November 2014.