SAN FRANCISCO — Twitter Inc on Thursday filed a federal lawsuit to block an order by the U.S. government demanding that it reveal who is behind an account opposed to President Donald Trump's tough immigration policies.

Citing freedom of speech as a basis for not turning over records, Twitter filed the lawsuit in federal court in San Francisco and said that the account, @ALT_uscis, claimed to be run by at least one federal immigration employee. The acronym CIS refers to U.S. Citizenship and Immigration Services, and the account describes itself as "immigration resistance."

Trump has vowed to build a wall along the U.S. border with Mexico and has promised to deport millions of illegal immigrants.

Following Trump's inauguration in January, anonymous Twitter feeds that borrowed the names and logos of more than a dozen U.S. government agencies appeared to challenge the president's views on climate change and other issues.

A Twitter spokesman declined to comment on whether the government demanded information about other accounts critical of Trump.

Twitter, which counts Trump among its active users, has a record of litigating in favor of user privacy.

"The rights of free speech afforded Twitter's users and Twitter itself under the First Amendment of the U.S. Constitution include a right to disseminate such anonymous or pseudonymous political speech," Twitter said in the lawsuit. (PDF)

The U.S. Department of Homeland Security, which is a defendant in the lawsuit, declined to comment on pending litigation. The Justice Department, which typically represents federal agencies in court, also declined to comment.

Esha Bhandari, a staff attorney with the American Civil Liberties Union, which is representing the Twitter user in the case, said the government's request was highly unusual. Requests for social media account information from the U.S. government typically involve national security or criminal charges, she said.

"We have seen no reason the government has given for seeking to unmask this speaker's identity," Bhandari said, adding that the right to anonymous speech against the government is "a bedrock American value" strongly protected under the First Amendment of the U.S. Constitution.

Shortly after the lawsuit became public, @ALT_uscis tweeted a copy of the First Amendment and a picture of part of the lawsuit to its 61,000 followers, an increase of about 28,000 in a few hours.

For weeks the account has posted criticism of the administration. It tweeted a parody of the game "bingo" for "right-wing idiots," said that some anti-immigration advocates must have been dropped on their head at birth, and mocked Trump for not giving more of his wealth to charities.

Twitter said it received an administrative summons last month demanding that it provide records related to the account. (PDF)

A copy of the summons filed with the lawsuit says the records are needed for an investigation to ensure compliance with duties, taxes and fines and other customs and immigration matters.

It was not immediately clear how the anonymous account fit into those laws and regulations, and Twitter might have a strong case that the summons was improper, said Paul Alan Levy, staff attorney at Public Citizen Litigation Group who specializes in online privacy and free speech issues.

"I don't think there is any way for the government to come out of this looking good," Levy said.

The lawsuit may also be savvy public relations for Twitter, said Jane Kirtley, law and journalism professor at the University of Minnesota.

“Twitter and other social media sites make promises to users about protecting anonymity. This is a way for Twitter to say, ‘See, we are standing up for your rights,’” Kirtley said.

The social media company has a history of challenging government demands for information on its users, including a 2012 demand from New York prosecutors about an Occupy Wall Street protester. In that case, Twitter was forced to hand over tweets from the protester to a judge who threatened the company with sanctions, and the protester pleaded guilty to disorderly conduct.

Twitter sued the U.S. Department of Justice in 2014, seeking permission to publicly disclose more information about requests it gets from U.S. authorities for information about its users. The lawsuit was partly dismissed last year.

Among the lawyers representing Twitter in the latest case is Seth Waxman, a former high-ranking Justice Department official under President Bill Clinton.

(Reporting by David Ingram; Additional reporting by Dustin Volz and David Shepardson in Washington and Melissa Fares, Joseph Ax and Alison Frankel in New York; Editing by Lisa Shumaker)