Citing freedom of speech as a basis for not turning over records, Twitter filed the lawsuit in the federal court in San Francisco on Thursday saying the account @ALT_uscis is claimed to be run by at least one federal immigration employee.

The acronym CIS refers to US Citizenship and Immigration Services, and the account describes itself as "immigration resistance."

Trump has vowed to build a wall along the US 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 US 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 favour of user privacy.

Related Articles

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

The US Department of Homeland Security and the US Justice Department both declined to comment.

Esha Bhandari, a lawyer 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 US 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 US 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.