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.
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.