New Zealand’s government has passed a law that will make medical marijuana widely available for thousands of patients over time, after years of campaigning by chronically ill New Zealanders who say the drug is the only thing that eases their pain.

The legislation will also allow terminally ill patients to begin smoking illegal pot immediately without facing the possibility of prosecution.

The health minister, David Clarke, said thousands of New Zealanders were living with chronic and end-of-life pain and the evidence that marijuana could safely help ease their suffering was sound.

The law would also pave the way for New Zealand companies to manufacture medicinal cannabis products for both the local and international market, an industry which is being touted as a potential game-changer for deprived Māori communities on the east coast of the North Island, who hope to turn the thriving illegal industry into a thriving legal one.

“People nearing the end of their lives should not have to worry about being arrested or imprisoned for trying to manage their pain,” Clarke said.

“This is compassionate and caring legislation that will make a real difference to people … they can use illicit cannabis without fear of prosecution.”

The measures come ahead of a planned referendum on recreational marijuana use, which the government has pledged to hold within two years, as part of their confidence and supply agreement with coalition partner the Greens.

The new law allows much broader use of medical marijuana, which was previously been highly restricted and subject to approval by the health minister.

The campaign to make marijuana legal applauded the government for passing the legislation within their first year in office.

“New Zealanders will take this as encouragement that we don’t need to be stuck in the past,” said Sandra Murray, campaign manager for the #makeitlegal campaign.

“We are now only two steps behind the rest of the world when it comes to sensible cannabis laws and with the upcoming referendum, we are on track to become an example of how to get it right.”

Marijuana use is common in New Zealand and police largely turn a blind eye to small, recreational use of the drug, with some politicians even admitting to using it in their youth.

Today Aotearoa New Zealand finally passed legislation to create a legal, local #medicinalcannabis scheme. #nzpol pic.twitter.com/Pwfesu4ncS — Chlöe Swarbrick (@_chloeswarbrick) December 11, 2018

The opposition National party said the government had decriminalised cannabis “by stealth”, and slammed the move as “lazy and dangerous”.

“We support medicinal cannabis but strongly oppose the smoking of loose leaf cannabis in public. Smoked loose leaf is not a medicine,” said the Nationals’ spokesperson on health, Shane Reti.

Patients wanting to use marijuana for conditions like chronic pain will have to wait a year until a new set of regulations, licensing rules and quality standards are put in place.