An Egyptian youth arrested two years ago for wearing a T-shirt with a slogan against torture was released early Friday, his brother said.

Mahmoud Mohammed Ahmed, 20, was freed from a Cairo police station more than 12 hours after a court in the Egyptian capital upheld another court's order to release him. The prosecution had appealed the earlier ruling.

Wearing a white T-shirt and a matching baseball cap, he stepped out of the station to a welcome by his brother, Tarek Mohammed Ahmed, and a small crowd of lawyers, rights activists and friends.

Mahmoud was 18 and a high school student when he was arrested on Jan. 25, 2014 -- the third anniversary of the uprising that toppled autocrat Hosni Mubarak and a day that saw deadly street clashes between police and protesters.

He was detained on his way home from a rally marking the anniversary, at a checkpoint north of Cairo, and accused by police of taking part in unauthorized demonstrations, possession of explosives and paying money on behalf of the now-banned Muslim Brotherhood group to others to take part in protests. He was never formally charged.

When arrested, he was wearing a T-shirt with the slogan "A nation without torture" -- which turned his case into a cause celebre for Egyptian rights activists campaigning for an end to police abuses.

His brother and one of his lawyers, Mukhtar Munir, have maintained that Mahmoud was tortured in the early stages of his detention and deprived of many of his rights. He had leg surgery in 2010 for a condition stemming from a bad childhood fall. In detention, the condition of the leg deteriorated because of lack of adequate medical attention, they said. He now limps and walks slowly, using a cane for support.

Since Mahmoud's arrest, his older brother Tarek, also an activist, has campaigned for his release, using social media, TV appearances and press interviews.

Mahmoud's letters to friends and relatives smuggled out of prison and seen by the AP testify to both his young age and activism. They are adorned by drawings of Mickey Mouse, smiley faces or flowers. One letter to his brother says: "I am positive that the day will come when we will do everything without fearing prison or oppression." In another note, he wrote: "We will die when we stop dreaming."

His detention was part of the crackdown overseen by President Abdel-Fattah el-Sissi who the year before, as military chief, led the July 2013 ouster of Egypt's elected president, the Islamist Mohammed Morsi, following mass protests against his divisive rule.

The crackdown has primarily targeted Morsi's Brotherhood supporters but secular, pro-democracy activists have not been spared. Mahmoud's case drew the attention of rights groups at home and abroad, mostly because of his young age and the circumstances of his arrest.

Amnesty International in January said his detention was an "utter disgrace" and an "affront to justice."

"No one should be arrested or detained simply because of slogans on the T-Shirt or scarf they have chosen to wear, let alone imprisoned for two years and facing torture and other ill-treatment in detention," said Said Boumedouha, Amnesty's deputy director for Mideast and North Africa.