Ousted president Hosni Mubarak’s former prime minister was cleared of a final slew of corruption charges Thursday, paving the way for his return to Egypt now that the elected government that once sought to prosecute him is no longer in power.

Ahmed Shafiq ran for president last year and finished second to Mohamed Morsi in the country’s first democratic presidential election. He subsequently faced trial in five criminal cases. He was acquitted Thursday, along with Mubarak’s sons, of engaging in illegal land acquisitions.

Hours later, a Cairo judge threw out a fifth and final case in which Shafiq, a former commander of Egypt’s air force, and other air force officers were charged with corruption.

Judicial authorities said the Cairo Criminal Court sent the case back to Egypt’s attorney general, who may choose to refile or abandon it. The attorney general’s office declined to comment.

But a Shafiq aide said Thursday that Shafiq, who fled to the United Arab Emirates shortly after Morsi’s election, was optimistic.

“I don’t think the attorney general will raise [the case] again,” said Ahmad Sarhan, who also had served as Shafiq’s campaign adviser. He said Shafiq seemed “very relaxed” during a phone call before the verdicts.

Sarhan also said that the court’s dismissal of the two cases provides an opening for Shafiq’s return to Egyptian politics.

“He’s going to return to Egypt soon,” Sarhan said, adding that Shafiq plans to “put his full energy” into building his new political party, the Egyptian National Movement — “trying to grab as much as he can for the next parliament.

Shafiq told the Reuters news agency in September that he would not run for president if the commander of Egypt’s armed forces, Gen. Abdel Fatah al-Sissi, decided to run. Sissi, who instigated Morsi’s ouster in a July 3 coup, has not said whether he will seek the presidency.

Shafiq is one of several members of Mubarak’s regime, including Mubarak himself and the head of his former ruling party, who have been acquitted or had verdicts overturned since Morsi’s ouster. They were charged after the 2011 uprising that ended Mubarak’s three decades of autocratic rule.

Egyptian security forces, meanwhile, have arrested thousands of Morsi’s Islamist supporters and political allies. The Muslim Brotherhood, which backs Morsi, says the charges against them are politically motivated.

Essam Sultan, an Islamist politician who filed the charges against Shafiq under Morsi’s rule, is in jail, facing charges of inciting violence. In September, Sultan was convicted of insulting Shafiq and was ordered to pay a fine of about $5,800.

Morsi is being tried on a charge of inciting murder. On Wednesday, Egypt’s attorney general said the former president would also face charges of conspiring with foreign militant groups.

In recent weeks, the military-backed government has gone after human rights groups and liberal youth activists for protesting the extensive powers of Egypt’s military, which have been codified in a new draft constitution. The activists also object to a new law that effectively bans protests.

Security forces raided a human rights group in Cairo overnight Wednesday. On Thursday, police arrested Mohamed Adel, one of three of the country’s most prominent non-Islamist youth activists who face charges of violating the new protest law.

Sharaf al-Hourani contributed to this report.