There have been disruptive scenes at the High Court in Uganda which was due to hear a bail request for the arrested opposition leader, Kizza Besigye.
The opposition were furious about the presence of the armed men
Fourteen of his co-accused were granted bail, but they refused to leave the court when a group of mysterious armed men in black T-shirts arrived outside.
They were returned to prison and Dr Besigye, charged with treason and rape, failed to make a court appearance.
Two days of clashes in the capital followed Dr Besigye's arrest on Monday.
President Yoweri Museveni has accused opposition politicians of inciting the riots and said he would use all means to stop the them.
The BBC's Will Ross in Kampala says after the judge granted the defendants bail, armed men - not in regular army uniform - arrived in the High Court compound in minibuses.
They then stood at the exit to the High Court waiting for treason suspects to leave, our correspondent says.
Officials from Dr Besigye's Forum for Democratic Change (FDC) said it was too dangerous to release the accused to the unknown gunmen.
Opposition onlookers and lawyers were furious, accusing the military of invading the High Court, our correspondent says.
Earlier, Dr Besigye's wife Winnie Banyima, a former MP, told the BBC she thought the charges against her husband were "trumped up" and said he had suffered intimidation since he declared his intention to challenge the president in polls next year.
Meanwhile, Mr Museveni's National Resistance Movement is meeting this week and is expected to endorse him as its presidential candidate in next year's elections.
Earlier this year, the UK and other donors withheld some aid to Uganda after the constitution was amended to allow Mr Museveni to run for a third term
'He will stand'
Dr Besigye returned from four years of exile last month to huge crowds of cheering supporters.
Used to be Museveni's doctor
March 2001: Ran against Museveni
August 2001: Went into exile
Oct 2005: Returned home
Nov 2005: Charged with treason, rape
John Nagenda a senior adviser to the president told the BBC he believes Dr Besigye will be able to take part in presidential elections in March.
"I don't think he'll be in jail when the election comes.... I think he will be given bail. I think [he will] stand," Mr Nagenda told the BBC's Newshour programme. If found guilty of treason, he and 22 co-accused could face the death penalty.
Dr Besigye has previously denied allegations that he is linked to rebel groups.
The rape charge dates from an incident in 1997, allegedly involving the daughter of a friend.
Once Mr Museveni's doctor, Dr Besigye ran against the president in 2001 before fleeing after the elections, saying his life was in danger.