AUGUSTA, Maine — Dan Brown, the Blue Hill dairy farmer whose legal fight against state regulators spawned protests and a slew of anti-regulation ordinances in towns across Maine, has lost his battle in the state’s highest court.

The Maine Supreme Judicial Court on Tuesday issued a ruling against Brown, upholding a lower court’s decision that he had broken the law by selling raw milk from his unlicensed, uninspected Gravelwood Farm.

Brown’s fight had become a cause celebre among advocates for a deregulated local food movement. They would often rally in his name, declaring at various points that “We are all Farmer Brown.” The Blue Hill farmer, clearly dispirited on Tuesday, said he’s not sure what his next step will be, but his gut tells him “enough is enough.”

“Farmer Brown has had his 15 minutes of fame. It’s time for Dan Brown to have a life again,” he said. “We still have our life here. We still are trying to keep a kind of farm life, even though it’s not a farm business anymore.”

The high court heard oral arguments in May. Local food activists and some lawmakers rallied around Brown and drank raw milk on the steps of the courthouse.

Brown had been selling raw milk, and other food products, from a farmstand and at local farmers markets since 2006. Brown was initially sued by the state in 2011. The attorney general held that Brown was required by law to have a milk distributor’s license and a food establishment license, and to clearly and explicitly label his bottles to indicate that the contents were unpasteurized.

In 2013, Justice Ann Murray of Hancock County Superior Court fined Brown $1,000 for failing to comply with state law, and barred him from selling any more milk until he obtained the proper licenses. Tuesday’s Supreme Court ruling affirmed Murray’s judgment.

Brown has since filed for bankruptcy and largely converted his farm to a homestead operation, providing food for his family only.

A state employee in 2006 told Brown that he did not need a license to sell raw milk from his farm stand. In 2009, when oversight of Maine’s dairy farms was shifted to a different state agency, the state renewed its enforcement of existing licensing laws, and Brown was notified that he was out of compliance.

The farmer argued in court that it was illegal for the state to change the rules, because he’d relied on its guidance in establishing his business. He said it would have cost tens of thousands of dollars to build a facility that could meet state requirements.

Writing the unanimous opinion of the Supreme Court, Justice Donald Alexander said that the state’s interest in ensuring the safety of dairy products sold in Maine is paramount.

“The court determined that, under the totality of the circumstances, the public health implications of permitting Brown to sell milk without a license outweigh the injury to Brown to obtain a license,” he said.

Brown also had argued that a local Blue Hill rule exempted him from state licensing requirements. Blue HIll’s “local food sovereignty” ordinance sought to shield resident farmers from state oversight as long as they only sold their products directly to consumers.

The Supreme Court said that Blue Hill’s ordinance could only exempt Brown from any local licensing and inspection, not those imposed by the state.

Alexander wrote that the court sought to interpret Blue Hill’s ordinance in a way that would prevent it from violating the Maine Constitution, which grants to municipalities only the authority to pass ordinances that don’t contradict existing state law.

In this case, the Legislature has claimed authority to regulate the production and sale of dairy produces, so Blue Hill’s anti-regulation ordinance was interpreted by the court only to nullify local regulation.

The ruling by the court renders Blue Hill’s ordinance effectively toothless. That will be seen as a huge blow not only to local food sovereignty advocates in that town, who intended their law to shield local farmers from state regulation, but to activists in several other Maine towns that have passed similar local ordinances.

Activists, who have long attempted to get Maine courts to weigh in on the relative health risks of raw milk vs. pasteurized milk, will also be dismayed by a footnote in the court’s ruling, where the justices declined to pass judgment on the merits of going raw.

“Brown also suggests that unpasteurized milk is as safe to consume as pasteurized milk, that state policies favoring the pasteurization of milk are unsound and that the state’s licensing requirements for the production and sale of raw milk are unjustified. These policy arguments are more appropriately addressed to the Maine Legislature,” said Alexander.

Jessie Dowling, owner of Fuzzy Udder Creamery in Whitefield, produces about 150 pounds of goat, sheep and cow cheese every week. She’s a licensed cheesemaker, but says she thinks state law should carve out an exception to deregulate the smallest producers.

Still, she thinks Brown and his supporters have taken the cause a small step too far.

“It’s important for licensed producers to defend the right for small guys to produce what they want, but it’s important where the line is drawn,” she said Tuesday. “I think it’s unfortunate that Dan Brown drew the line where he did and became the poster child for this movement.”

Dowling worked with lawmakers this session in an effort to pass a new law that would allow for the sale of dairy products from unlicensed producers, as long as they only sold their product from the farm, and did not advertise — not even with a sign at their farmstand.

That way, she said, a farmer with just one cow, producing more milk than the farmer could consume, could make a little money off the surplus, but not enter the wider, public market. Dowling said that’s not any different than going to a friend’s house for dinner and trusting they knew how to safely handle raw meat.

The bill ultimately failed in the Legislature, where Brown and Dowling both said future fights for local food sovereignty are likely to take place. There, working with lawmakers, they see hope for a regulatory system that’s more scale-appropriate.

Brown said he could be more effective there than as the public spokesman for a whole movement.

“I’m perfectly happy to go down to Augusta and work behind the scenes, but Farmer Brown is done,” Brown said.