Freeman Mbowe, the chairman of Tanzania's main opposition party Chadema, has been released on bail after winning an appeal against a contempt of court ruling.
Mr Mbowe was freed alongside his co-accused Esther Matiko, a Chadema MP, after spending nearly four months in prison.
The two had been denied bail in November last year for failing to show up for a court hearing.
At the time, Mr Mbowe said be had been taken ill while Ms Matiko said she had been on parliamentary duty outside the country.
The Chadema chairman, Mrs Matiko along with seven other top party leaders are facing charges of sedition, incitement to violence and holding an "illegal rally" in February 2018 that led to the death of a female student, who was killed by a police stray bullet.
In an appeal by the pair, High Court Judge Sam Rumanyika ruled Thursday that their rights had been violated, and ordered their immediate release on bail.
"I have never seen such a case in all my time as a judge," Mr Rumanyika said, adding it was "dangerous to deny an accused bail without a valid reason."
"I order that Mr Mbowe and Mrs Matiko be freed immediately," the judge ruled.
They must report to the court once a month until their appearance with the seven co-accused in the protest trial.
Six opposition parties in Tanzania vowed in December to join forces in a campaign against what they termed the "dictatorship" of President John Magufuli.
Critics say Dr Magufuli has unleashed a wave of oppression since his election in 2015, cracking down on opposition figures, the media, and gays.
In November, the United States accused the Tanzanian government of fostering "an atmosphere of violence, intimidation and discrimination".
The European Union, Tanzania's biggest development partner, also said it would review its financial support -- more than $100 million (88 million euros) per year -- in response to moves undermining "human rights and the rule of law."