The Ugandan MP and pop star Bobi Wine has been charged with treason in a civilian court shortly after a military court freed him.
Bobi Wine, whose real name is Robert Kyagulanyi, was immediately re-arrested after being released.
His lawyers say he has been assaulted in detention, which the military and President Yoweri Museveni deny.
He was detained along with 30 others ahead of last week’s by-election in the north-western town of Arua.
The arrests have raised tension across the country and sparked protests. Police have sealed off the homes of a number of opposition politicians, and high-profile opposition figure Kizza Besigye has been arrested in the capital Kampala.
- Africa Live: How the day unfolded
- The Afrobeats MP standing up to Uganda’s long-time leader
- Celebrities call for Uganda star’s release
The BBC’s Catherine Byaruhanga, who was at court in the northern town of Gulu, says he was unable to stand by himself and there were moments when he was visibly in pain.
His lawyer said he needed “urgent medical care”, Uganda’s New Vision newspaper reported.
After being freed and told that charges of unlawfully possessing firearms were dropped by the General Court Martial, Bobi Wine was told by his lawyer that he was under arrest again and he was put into a police vehicle with his wife to be taken to the Chief Magistrates Court.
He was remanded in custody until 30 August, when he is due back in court.
There have been protests against his detention in Uganda and calls by global stars such as Chris Martin, Damon Albarn and Angelique Kidjo for his release.
On Tuesday the Ugandan military apologised after soldiers were caught on film beating up a journalist who was covering a demonstration supporting Mr Wine.
Why was Bobi Wine arrested in the first place?
He was detained in Arua, where President Museveni, who has been in power since 1986, was campaigning.
The authorities say opposition lawmakers led supporters to attack the president’s convoy with stones. Bobi Wine’s driver was later shot dead.
The ruling party went on to lose the seat to opposition candidate Kassiano Wadri, who also remains in custody and is facing treason charges.
The authorities say weapons and ammunition were found in Bobi Wine’s hotel room.
The charges are widely viewed as politically motivated and aimed at silencing a prominent critic of the president. The US decried the “brutal treatment” of MPs, journalists and others by security forces.
Who is Bobi Wine?
He is a successful Afrobeats star, known for a repertoire of catchy tunes that touch on poverty and social justice issues.
The lifestyle and love life of the self-styled “ghetto president”, which refers to his upbringing in the poorest slum of the capital, became tabloid fodder.
He shifted gears in 2017, cutting off his dreadlocks and donning sharp suits as he turned his eye to Ugandan politics.
He went on to beat more established candidates by a landslide in a by-election and became the MP for Kyadondo East in central Uganda.
Why is he so popular?
In a country where more than three-quarters of the population is under the age of 30, Bobi Wine might have demographics on his side.
He has been described as a magnetic presence and a skilled orator, who has the potential to galvanise the country’s youth.
He told the BBC in 2017 that he wanted to be the voice of the younger generation. “I’m here to give young people confidence,” he said.
He might also have a knack for being kingmaker. In the past year, three candidates backed by Bobi Wine have won parliamentary seats in by-elections.
Is he upsetting the status quo?
Yes. His popularity could make him President Museveni’s biggest challenger in the 2021 elections.
He protested with activists against a social media tax introduced to boost state revenue, which the government has since backtracked on.
Bobi Wine was also one of the leading critics of a push to scrap the constitutional upper age limit, set at 75, for presidential candidates.
But the change was signed into law and will allow 74-year-old Mr Museveni to run for a sixth term in 2021.
Uganda’s Bobi Wine: Pop star MP charged with treason