The National Rifle Association sued San Francisco on Monday, less than a week after the city’s board of supervisors declared the group a terrorist organization and moved to limit relationships with companies that do business with the N.R.A.

The suit alleges that the city is violating the N.R.A.’s First Amendment speech rights and has effectively moved to “blacklist anyone linked to the N.R.A.” In a statement, the N.R.A.’s outside counsel, William A. Brewer III, called the city’s action “an assault on all advocacy organizations across the country.” The lawsuit was filed in United States District Court in San Francisco.

Supervisor Catherine Stefani of the San Francisco board introduced the measure on July 30, on the heels of a shooting at a garlic festival in Gilroy, Calif., that left three dead and more than a dozen others injured. Since then, a spate of mass shootings in Texas and Ohio have renewed calls for expanded background checks of gun buyers, but the N.R.A. has rejected such calls and thus far persuaded President Trump to do so as well.

Ms. Stefani, a lawyer, said in an interview on Monday that she believed the measure would withstand legal challenges.