A federal appeals court ruled a San Francisco ordinance requiring health warnings on advertising for sugary drinks violates the First Amendment, in a victory for national beverage makers whose products have come under increasing government scrutiny.

The unanimous ruling by a full court of 11 judges on the Ninth U.S. Circuit Court of Appeals on Thursday affirms a decision by a three-judge panel of the court in 2017, which the city of San Francisco appealed.

The...