HELENA, Mont. — Medical marijuana dispensaries across Montana have closed their doors as new restrictions took effect Wednesday that limit pot providers to three patients apiece, leaving thousands of pot users registered with the state without a legal way to buy the drug.

The restrictions begin after five years of unsuccessful court battles to overturn the 2011 state law that rolled back much of a voter-approved law that brought medical marijuana to Montana in 2004. It is one of the most significant rollbacks by the 25 states and Washington, D.C., that allow marijuana to be used for medical purposes.

Medical marijuana advocates estimate that over 12,000 patients are losing legal access to pot because their providers did not choose them as one of their three patients. There were 13,190 registered patients at the end of July, says the Montana Department of Public Health and Human Services.

Dispensaries posted Facebook messages to their patients that they were closing Tuesday. Some offered their products at discounts, such as Lionheart Caregiving’s $3 marijuana brownie sale, while others gave away inventory before closing down.

“Everybody’s shutting down,” said Kate Cholewa, government relations director for the Montana Cannabis Industry Association. “It’s over.”

The Montana Supreme Court this year upheld three key provisions of the 2011 state law: marijuana providers can sell to no more than three registered users each; doctors who recommend the drug to more than 25 patients in a year must be automatically reviewed; and marijuana advertising is banned.

Enforcement of the new restrictions will be the duty of sheriff’s offices and local police departments. In Gallatin County, which had 130 medical marijuana providers in July, Sheriff Brian Gootkin said he just doesn’t have the manpower to knock on doors to confirm that everyone is following the law.

Instead, the department is sending out letters to providers to make sure they know what is required of them.

“We’re taking the approach that we’re hoping they do abide by the law, and if we find out otherwise, we will be visiting with them,” Gootkin said.

The state health department, which oversees the medical marijuana program, has already spent months contacting patients and providers about the changes, department spokesman Jon Ebelt said.

Only 1,900 patients told the department they kept their provider, found a new one or plan to grow their own, Ebelt said. Another 8,600 registered patients have not told the department what they plan to do, and health officials will issue them 30-day cards to allow them more time to make plans.

Out of the 488 registered providers in the state at the end of July, 304 sold marijuana to more than three patients. Ebelt said 305 providers have told the department that they will continue to provide marijuana to up to three patients.

The rest either did not respond or asked to be removed from the state registry, Ebelt said.

Many patients who are in hospice or have serious illnesses aren’t strong enough to grow their own marijuana, while others don’t have the first clue how to do it, said Katrina Farnum, who runs Garden Mother Herbs in Missoula.

As a result, some of her patients are leaving the state, while others have said they may have to go on opioids or try to buy the drug on the black market, she said. Farnum was one of the providers who gave patients marijuana for free before closing, up to the legal limit of 28 grams.

Patients and providers alike have pinned their hopes on a ballot initiative in the November election that would reverse many of the restrictions put into place. Dispensaries, in their Facebook farewell messages, urged their patients to vote for the measure and vowed to re-open if it passes.

“The patients of the state of Montana are counting on voters to turn out,” said Tayln Lang, a patient from Hamilton who is backing the ballot initiative.

But an error in the initiative could delay its implementation by more than half of a year, even if it passes. Initiative organizers did not update the section of the proposed bill’s effective date in the most recent draft, leaving the bill to read that the three-patient limit would not be lifted until June 30.

Organizers called that a clerical error that can be corrected after the election, but the chief legal counsel for the Montana Legislative Services Division said it was a substantive change that would require legislative approval.