SAN FRANCISCO (Reuters) - A secret U.S. court overseeing government domestic surveillance activities has sided with Yahoo Inc and ordered the Obama administration to declassify and publish a 2008 court decision justifying Prism, the data collection program revealed last month by former security contractor Edward Snowden.

The ruling could offer a rare glimpse into how the government has legally justified its spy agencies' data collection programs under the Foreign Intelligence Surveillance Act (FISA).

Judge Reggie Walton of the Foreign Intelligence Surveillance Court issued Monday's ruling. The government is expected to decide by August 26 which parts of the 2008 opinion may be published, according to a separate court filing by the Justice Department.

Controversial U.S. data collection activities are overseen by the Foreign Intelligence Surveillance Court and its appeals body, the Foreign Intelligence Surveillance Court of Review. Both have been shrouded in secrecy since their creation more than three decades ago.

The 2008 ruling stemmed from Yahoo's challenge of the legality of broad, warrantless surveillance programs like Prism.

In June, after Snowden leaked information about Prism to the Washington Post and the Guardian newspapers, Yahoo's lawyers asked the courts and government to declassify and publish decisions upholding the constitutionality of the program.

Legal experts who follow surveillance cases said the 2008 ruling may not reveal any strikingly novel legal reasoning by the government or the courts. But civil liberties advocates said the significance of the ruling may lie in the court's decision itself to declassify the previously secret 2008 ruling.

"Unless the public knows what the laws mean, it can't really assess how much power (it has) given its government," said Patrick Toomey, a national security fellow at the American Civil Liberties Union.

Monday's ruling "is a suggestion that the FISA court is primed now to consider the government's assertion of the necessity of secrecy," Toomey said. "It's a promising first step."

The decision is also a victory for Yahoo Inc, which said in a statement on Tuesday that it was "very pleased" with the court's ruling.

"Once those documents are made public, we believe they will contribute constructively to the ongoing public discussion around online privacy," Yahoo said.

Other Internet companies, including Google Inc and Facebook Inc, began participating in Prism in early 2009 soon after Yahoo lost its appeal before the Foreign Intelligence Surveillance Court of Review.

It is not known if Yahoo, or any other party, has sought to appeal to the U.S. Supreme Court.

A number of major U.S. Internet companies, including Microsoft, Google and Facebook have asked the government for permission to disclose the number of national security-related user data requests they receive.

On Tuesday, Microsoft published an lengthy letter to U.S. Attorney General Eric Holder asking for greater freedom to publicly discuss how it turns over user information to the government. The letter was a response to a Guardian report that said Microsoft had given authorities the ability to circumvent encryption of Outlook emails and to capture Skype online chats. Microsoft has contested the report, saying it has "significant inaccuracies.

Until recent weeks, Yahoo was prohibited from discussing its activities in the secret courts or even acknowledging the existence of its legal challenge.

The decision to release the 2008 ruling comes as Snowden remained at a Moscow airport, awaiting political asylum. On Tuesday, he applied for asylum in Russia.

In the coming weeks, the government is expected to publish the lower FISA court's 2008 ruling in the Yahoo case and legal briefs related to it. In an uncommon move, the U.S. had previously agreed to declassify a heavily redacted version of the appeals court ruling in the case.

The government has long argued on the grounds of national security that the surveillance courts' proceedings must be secret. Public and political reaction to Snowden's revelations has put pressure on that position.

In June, Senators Jeff Merkley, a Democrat from Oregon, and Mike Lee, a Utah Republican, introduced a bill that would require the government to declassify significant court rulings concerning the FISA court and its supervision of secret wiretapping programs.

"Americans deserve to know how much information about their private communications the government believes it's allowed to take under the law," Merkley said.