(Reuters) - Twitter Inc will not be able to reveal surveillance requests it received from the U.S. government after a federal judge accepted government arguments that this was likely to harm national security after a near six-year long legal battle.

FILE PHOTO: The Twitter logo is displayed on a screen on the floor of the New York Stock Exchange (NYSE) in New York City, U.S., September 28, 2016. REUTERS/Brendan McDermid/File Photo

The social media company had sued the U.S. Department of Justice in 2014 to be allowed to reveal, as part of its “Draft Transparency Report”, the surveillance requests it received. It argued its free-speech rights were being violated by not being allowed to reveal the details.

U.S. District Judge Yvonne Gonzalez Rogers granted the government’s request to dismiss Twitter’s lawsuit in an eleven page order filed in the U.S. District Court for Northern California.

The judge ruled on Friday that granting Twitter’s request “would be likely to lead to grave or imminent harm to the national security.”

“The Government’s motion for summary judgment is GRANTED and Twitter’s motion for summary judgment is DENIED,” the judge said in her order.

Twitter had sued the Justice Department in its battle with federal agencies as the internet industry’s self-described champion of free speech seeking the right to reveal the extent of U.S. government surveillance.

The lawsuit had followed months of fruitless negotiations with the government and had marked an escalation in the internet industry’s battle over government gag orders on the nature and number of requests for private user information.

Tech companies were seeking to clarify their relationships with U.S. law enforcement and spying agencies in the wake of revelations by former National Security Agency contractor Edward Snowden that outlined the depth of U.S. spying capabilities.

Twitter’s legal battle spanned the tenures of four U.S. attorneys general - Eric Holder, Loretta Lynch, Jeff Sessions and William Barr.

Through the use of confidential declarations, the Justice Department was able to show that revealing the exact number of national security letters from 2014, as requested by Twitter, posed a risk to national security, Friday’s order said.

Twitter said on Saturday it was disappointed with the court’s decision but added it “will continue to fight for transparency.” The statement did not give further details.