WASHINGTON—The Trump administration was accused of imposing a form of unconstitutional surveillance by requiring most U.S. visa applicants to provide information on social-media accounts, according to a lawsuit filed on Thursday—the latest legal test of the president’s campaign to more tightly control entry into the country.

The suit, which claims the requirement chills free speech, was filed by two documentary film organizations in a federal court in Washington.

It...