SAN FRANCISCO — Twitter sued the federal government on Thursday to block the unmasking of an anonymous account that has posted messages critical of the Trump administration and has claimed to have ties to a government agency.

The suit sets up a potential confrontation between the Trump administration and Twitter over digital privacy, a thorny issue that has driven a wedge between the technology industry and government in the past.

Twitter disclosed in a federal court filing on Thursday that it had received a summons directing it to reveal the identity or identities of those behind @ALT_USCIS, one of several so-called alt-accounts run by people purporting to be current or former federal employees. The @ALT_USCIS account, which quickly gained tens of thousands of followers, has frequently criticized the Trump administration’s immigration policies and enforcement actions.

Twitter said in its filing that it could not be compelled to disclose the identity or identities of whoever is behind the account. The company argued that the government’s directive and reasoning were unlawful, and that complying would have “a grave chilling effect” on the speech of alt-accounts that voice resistance to government policies.