General Court Martial in northern town of Gulu drops charges of illegal possession of firearms and ammunition.
Visibly frail Kyagulanyi walked out of the court with difficulty and was re-arrested by police shortly after being freed.
Kyagulanyi has been in detention since last week, along with four fellow MPs and dozens of others.
Ugandan independent MP Robert Kyagulanyi, known as Bobi Wine, has been charged with treason.
Mr Kyagulanyi, was on Thursday charged before Gulu Magistrate's Court for the stoning of the presidential motorcade in northwestern Arua town.
Earlier in the day, Mr Kyagulanyi appeared before the military court in Gulu on charges of illegal possession of firearms and ammunition.
But the General Court Martial withdrew the charges saying it was no longer interested in pursuing the case against the Kyadondo East MP.
“I have instructions that the proceedings before this court under Regulation 65 of the Uganda Peoples’ Defence Forces procedure be terminated and the accused person be released henceforth,” army prosecutor Major Raphael Mugisha told the court.
The visibly frail Mr Kyagulanyi walked out of the court using crutches and was re-arrested by the police.
Nicholas Opio, one of Mr Kyagulanyi's lawyers, described the court appearance as a “charade intended to continue abusing” his client’s rights.
“We arrived here at 4:00am, we waited, they brought him in at about 9:00am and said they were no longer interested in pursuing the matter but the magistrate’s court will take it over,” Mr Opio said in a telephone interview from Gulu.
President Yoweri Museveni was also sighted in Gulu as the trial was going on although his mission was not immediately clear.
Notably present at the court were Mr Kyagulanyi’s family, several opposition figures including former army commander Maj Gen Mugisha Muntu and the former opposition leader Winnie Kizza.
Mr Kyagulanyi has been in detention since last week, along with four other MPs and dozens of supporters.
The more than 30 people arrested with Mr Kyagulanyi following the chaotic Arua Municipality parliamentary by-election including MP-elect, Kassiano Wadri, remain in detention and are expected in court next week.
Police and the army deployed heavily in Kampala and cordoned off homes of several opposition leaders ahead of Mr Kyagulanyi’s court appearance.
Opposition leader Kizza Besigye was arrested as he attempted to leave his home in Kasangati and taken to Naggalama Police Station.
There have been several protests since the arrests last week. At least two people have died in the ensuing chaos.
Mr Kyagulanyi has been remanded to Gulu prison until August 30, 2018.