The four-judge panel said the Board of Health acted exceeded its legal authority when it tried to put a size limit on soft drinks served in restaurants, theaters, stadiums sidewalk food cars and many other places. According to the court, the board has the power to ban "inherently harmful" food from being served to the public, but sweetened beverages don't fall into that category.
It upheld a lower court decision that had delayed the measure before it took effect in March.
The ban was part of the city's war on diabetes and obesity. It would stop many eateries from selling non-diet soda and other sugary drinks in containers larger than 16 ounces.
Attorneys for the city said they plan to appeal.
"Today's decision is a temporary setback, and we plan to appeal this decision as we continue the fight against the obesity epidemic," Mayor Michael Bloomberg said in a statement.
Bloomberg leaves office at the end of the year, and it is unclear whether his successor will continue the legal fight. Only one candidate, Public Advocate Bill de Blasio, supports the ban. City Council President Christine Quinn, another candidate, has said she believes the city has the right to impose the ban, but wouldn't have done it herself. All the other leading candidates oppose it.
The Associated Press contributed to this report.