Morocco’s parliament voted to legalize the local cultivation of cannabis for medicinal and industrial use, in a potential victory for marginalized farmers in the world’s top exporter of the drug.

Morocco, where tens of thousands of people live off illegal marijuana cultivation, has debated legalization for the past decade, with advocates saying it would allow farmers to sell to the government instead of traffickers.

They found a powerful new ally in the interior ministry after 2017, when a major bout of unrest in the northern region of Rif exposed long-ignored socio-economic grievances. Rif accounts for a large share of the 475 sq km (183 square miles) planted with cannabis in the North African kingdom, and it is hoped that legalization will defuse tensions by ending the fugitive status of farmers there and providing economic relief.

A total 119 lawmakers cast ballots in favor of legalization and 48 against, the head of the chamber’s finance and economic affairs committee, Abdellah Bouanou, said by phone. His Justice and Development Party, or PJD -- Islamists who lead the coalition government -- voted against the bill.

King Mohammed VI has to approve the legislation before it can take effect. Recreational use, sale and production will remain illegal.

The global market for medicinal cannabis and cannabis-related products has boomed in recent years as more countries move away from outright prohibition of the plant whose derivatives can be used for therapeutic purposes.

The legal changes are expected to raise farmers’ revenues from growing the potent plant by around a third to 4.8 billion dirhams, or about US$543 million, by 2028, the ministry said in the bill. That figure is still a fraction of the street value of Morocco’s illegal trade in processed cannabis resin, which reaches 118 billion dirhams, equivalent to more than US$13 billion, for exports to Europe alone, according to minutes of the debate in parliament.

“The situation in the Rif is unstable,” Noureddine Mediane, a lawmaker from the region, told parliament last month, describing the drug as “green gold.”

“We want these farmers to plant their cannabis with their heads held high,” he said. “Should we also ban cultivation of raisins, figs and barley when these serve to make alcohol and beer?”

The reforms will end the legal limbo that’s seen thousands of farmers end up on police wanted lists while fields of the narcotic crop are grown so abundantly that they can be seen bordering the sinuous main road that cuts through the predominantly mountainous Rif. The kingdom “continues to be the most frequently mentioned source country for cannabis resin worldwide,” according to the United Nations Office on Drugs and Crime’s latest report.

In a statement, the PJD said the law was tabled without proper consultation, including with people in cannabis-growing areas and was “enmeshed in electoral considerations” ahead of September’s parliamentary polls. It questioned if the changes would help tackle poverty in Rif, where discontent is also linked to disputes over ethnic identity and political freedom.