KAMPALA, Uganda — The Ugandan government filed a treason charge on Thursday against a pop star-turned-lawmaker who is a major critic of the country’s longtime president.

Kyagulanyi Ssentamu, popularly known as Bobi Wine appeared weak and struggled to walk into court. His lawyer said he was severely beaten in custody, an accusation the government denied.

It was the first time Mr. Ssentamu had been seen in public since his Aug. 13 arrest that outraged leading musicians from around the world. He clenched his fists as he greeted supporters and a colleague wrapped a scarf in the colors of Uganda’s flag around his shoulders.

Mr. Ssentamu, 36, was arrested with other lawmakers while campaigning for a candidate, Kassiano Wadri, in the northwestern town of Arua. He had been charged with illegal possession of firearms after he was accused in the stoning of President Yoweri Museveni’s motorcade. The president, too, was campaigning in Arua, for a rival candidate who eventually lost.