The former chief of Sudan's powerful intelligence service, who faced a possible death sentence for his alleged role in a coup plot, was freed under an amnesty on Wednesday, his lawyer said.
Salah Gosh "was released because of the amnesty given by President Bashir to all those who participated in the coup," Nabeel Adeeb told AFP.
The official SUNA news agency said Justice Minister Mohammed Bashara Dusa "issued a decision to release" Gosh along with another security officer, Major General Salah-Eddin Ahmed Abdalla Al-Toam.
Gosh walked free on the first day of the Muslim holy month of Ramadan.
He was the most high-profile figure detained last November in connection with the alleged coup plot against the 24-year regime of Omar al-Bashir.
Gosh is also one of the last to obtain amnesty, after soldiers and intelligence officers were earlier pardoned.
He was greeted with jubilation when he reached his upscale home.
Dressed in a traditional white jalabiya robe and turban, Gosh embraced the well-wishers.
"There is a crowd of people celebrating by sacrificing sheep," a witness said.
"Many of his relatives are here."
Gosh was charged in June under the criminal code and anti-terrorism law for his alleged role in the conspiracy, another lawyer, Ali Al-Saeed, said at the time.
Lawyers were seeking to have the charges thrown out before the case reached trial.
Gosh headed Sudan's national intelligence service for about a decade until Bashir replaced him in 2009.
During his tenure Gosh boosted cooperation with the American Central Intelligence Agency.
After leaving the security service he became presidential security adviser but was sacked in early 2011.
He had been pushing for dialogue with the political opposition.
In April Bashir pardoned about 15 security agents and military men who had been jailed for their roles in the coup plot.
Analysts say the case reflects a political struggle within Bashir's government.
Officials have never revealed more than vague details about the conspiracy which analysts said was linked to committed Islamist officers.
They had once firmly backed the regime but then accused the government of corruption and other problems which, they felt, marked a turn away from Islamic values.
Gosh himself is not part of the Islamist camp.
Bashir seized power in an Islamist-backed 1989 coup.
His government is facing a variety of challenges including a rebel offensive which widened this year with a push into a previously peaceful part of the country, in what analysts called a humiliation for the authorities.
Security has also deteriorated in far-west Darfur, while the economy continues to struggle with high inflation and a weak currency.
In April Bashir announced an amnesty for all political prisoners, which led to the release of some jailed opposition activists.
Last month, the Sudan Armed Forces rotated its top leaders as part of what official media called a routine shuffle.
A regional political expert told AFP that, while the SAF normally rotates its commanders every three years, Bashir "would like to be sure of their loyalty and professionalism".