The court accepted a petition by Fonseka´s wife requesting that his arrest be ruled illegal, and ordered the state to allow the former army chief family visits and medicines.[break]
"The court granted leave to proceed with the case," a court official told AFP.
Fonseka was arrested on Monday, two weeks after being trounced in presidential elections by the incumbent, President Mahinda Rajapakse. His detention triggered violent protests in Colombo and other parts of Sri Lanka.
The defence ministry says he is to be court-martialled on unspecified charges of conspiring against the government.
A lawyer for Fonseka said they regarded the supreme court decision to take up the petition as a major victory.
Hundreds of Fonseka supporters packed the courtroom, while police manned barricades outside.
Anti-riot squads had been put on alert after violent clashes Wednesday outside the court complex between Fonseka loyalists and ruling party activists.
Members of the elite Special Task Force commandos were also deployed in the city.
"We have taken preventive measures to ensure that law and order is maintained," police spokesman Prashanth Jayakody said.
Hundreds of lawyers marched outside the court after the hearing carrying placards demanding Fonseka´s release, but there were no clashes.
As the court proceedings got underway, the parliamentary opposition leader and former premier Ranil Wickremesinghe met with President Rajapakse to push for the former army chief´s freedom.
Wickremesinghe also insisted on being allowed to meet with Fonseka, who is detained at the navy headquarters in Colombo.
Fonseka´s wife says her husband needs medicines on a regular basis for the injuries he received in an April 2006 suicide bomb attack blamed on Tamil Tiger rebels.
An opposition statement said Rajapakse promised to take a decision on the fate of his former army commander, but only after military investigations into the alleged conspiracy against the government.
The government has yet to specify the charges Fonseka will face, but Defence Secretary Gotabhaya Rajapakse -- the president´s brother -- said he had clearly been plotting a military coup.
The arrest and detention of Fonseka has sparked international concern with the United States, the European Union and the United nations, among others, asking Colombo to ensure that due process was followed and that democracy was not undermined.
As the battlefield architect of the victory over the Tamil Tiger rebels last May, Fonseka was hailed as a national hero for finally crushing their 37-year campaign for an independent Tamil homeland.
But his bid to translate that military success into political power proved his undoing.
Fonseka, who quit the military in November, entered politics as the common opposition presidential candidate in the January 26 vote, which was easily won by Rajapakse.
Foreign Minister Paudyal discusses connectivity issue with Sri...