In a blow to commercial animal breeders and brokers, California pet stores will soon have to get their puppies, kittens and rabbits from shelters and rescue centers only.

Individuals can still buy from private breeders. But beginning in January 2019, it will be illegal for stores to do so. Violators will face a fine of $500.

The bill had strong support from several animal welfare organizations, which cheered it as a blow to “puppy mills” and “kitten factories” that mass produce animals for sale, often in inhumane conditions. It was written by two California Assembly members, Patrick O’Donnell and Matt Dababneh, both Democrats, and signed into law Friday by Gov. Jerry Brown.

California is the first state to pass such legislation, though it is following dozens of its own cities and jurisdictions, which have passed similar measures on a smaller scale.

In March, Roseville, Minn., forbid the sale of dogs and cats at pet stores.

“Because pet stores are one step removed from the breeding of the animals they sell, store owners rarely know the breeding conditions of their animals,” a fact sheet for the California legislation said. “In many cases, puppy mills house animals in overcrowded and unsanitary conditions without adequate food, water, socialization or veterinary care.”

Opponents of the measure argued that the bill painted large “puppy mills” and responsible backyard dog breeders with the same broad brush.

Mike Bober, the president of the Pet Industry Joint Advisory Council, a national advocacy group, called it “well-intentioned but misguided” in a video last month, adding that it would jeopardize hundreds of jobs.

But the number of for-profit pet stores in California had been dwindling long before this bill was signed, said Boris Jang, who owns the Puppy Store in Santa Ana, Calif.

He expects the new law will put him out of business.

Jang said he once worked with animal brokers but stopped about four years ago after learning that the dogs might be coming from commercial breeders where animals suffered.

Since then, he said, the Puppy Store has offered a mix of dogs. About half come from shelters or rescue centers; the rest, which are sold for profit, come from small local breeders or people who have a litter they do not know what to do with. He said that if he had to switch entirely to shelter and rescue dogs, he could not afford his lease.

Still, Jang said he understood lawmakers’ intentions. “Their heart is in the right place, but their thinking is a little shortsighted.”

After the bill easily passed in California’s Senate and Assembly last month, the American Society for the Prevention of Cruelty to Animals praised the state for taking action where federal regulators had fallen short.

“By cutting off the puppy mill pipeline that moves cruelly bred animals from across the country into California pet stores, A.B. 485 will also help prevent California consumers from being duped into purchases that contribute to unconscionable animal ‘production’ and suffering,” the organization said.

But Ben Ashel, a pet store owner in Agoura Hills, Calif., said the new law might have unintended effects by motivating more consumers to order dogs online or find sneakier ways to acquire the breeds they want.

His store, Puppy Heaven, specializes in matching owners with tiny dogs — teacup Yorkies and toy Maltipoos — and has a celebrity clientele. He said he was not sure what he would do once the law takes effect.

“It takes the freedom of choice from people who want to get a puppy. They don’t want to get someone else’s unwanted dog or something of that nature,” he said, adding that some people need breeds that work well with children or accommodate allergies and other health issues.

“They just want to start fresh with a puppy, and this law makes it very, very difficult.”