Amina Sboui, a young Tunisian activist with the topless protest group Femen, was released from jail on Thursday pending her trial for desecrating a cemetery.
Sboui left the women's prison in Sousse, south of Tunis, where she has been held since May 19, and her supporters issued a photo of her making a victory sign after she was freed.
"She is with her family," her lawyer Ghazi Mrabet told AFP. He said he hoped arrangements had been made to look after the 18-year-old's security, as radical Islamists have threatened Sboui in the past.
Several hours earlier, the Tunisian judiciary had ordered the release of the activist ahead of her trial.
Another of her lawyers, Halim Meddeb, described the court's move as a "big surprise."
The young woman faces trial for painting the word "Femen" on a cemetery wall in protest at a planned meeting of radical Sunni Muslim Salafists in the central city of Kairouan, an offence carrying a maximum sentence of two years in prison.
In recent weeks, however, the court dropped the charges of insulting a prison guard and public indecency against her.
Sboui's mother expressed her joy at the release, saying: "I will finally have her in my arms. The judiciary has showed that it is independent."
Mrabet also hailed the decision to free Sboui, saying "it shows that at least part of Tunisia's judiciary is independent."
Amina sparked both scandal and a wave of online support after she was threatened by Tunisia's increasingly active hardline Islamists for posting topless pictures of herself on Facebook earlier this year.
When the authorities arrested, her, a support network made up of NGOs, opposition politicians and human rights activists sprung up both in Tunisia and abroad.
Sboui's family said she suffered from chronic depression and had suicidal tendencies, and they prevented her from going out, claiming her safety was at risk.
But Sboui, who accused relatives of holding her in captivity and beating her, ran away from home in April and regularly appeared in public before her detention in May, although never topless.
The Femen movement, founded in Ukraine and now based in Paris, has flourished since 2010, with feminists around the world stripping off in protest at a wide range of issues linked to the mistreatment of women, but also against dictatorship.
At the end of May, three Femen activists -- two French and a German -- were arrested after bearing their breasts outside the main Tunis courthouse, in a demonstration of support for Amina.
The arrest of the three women triggered international condemnation and they were released a month later.
Secular opposition politicians have regularly accused the government, headed by the Islamist Ennahda party, of trying to curb freedom of expression.
But the authorities, and particularly Ennahda, have repeatedly denied that they want to roll back women's rights.
Tunisia has had the most liberal laws in the Arab world on women's rights since the 1950s.