A New York State appeals court on Thursday struck down most of a law that authorized fantasy sports in the state, dealing a setback to companies like FanDuel and DraftKings in one of their most lucrative markets.

The law, signed by Gov. Andrew M. Cuomo in August 2016, declared that fantasy sports did not constitute gambling and provided for consumer safeguards, minimum standards and the registration, regulation and taxation of daily fantasy sports providers.

In October of that year, the law was challenged by four New York residents who said they had been harmed by gambling, including one woman, Jennifer White, whose father regularly patronized off-track betting facilities in Western New York while her mother was besieged by loan sharks and creditors.

Their lawsuit argued that the law carved out an illegal exemption to the State Constitution’s prohibition on gambling, which forbids the practice except for a few exceptions, including at a limited number of horse tracks and casinos.