The Georgia General Assembly passed a bill late Tuesday that allows medical marijuana sales, providing a way for patients to buy the drug that they're already allowed to use.

The legislation, House Bill 324, licenses private companies and universities to grow medical marijuana. Then pharmacies and possibly dispensaries could sell it to the state's 8,400 registered medical marijuana patients.

The bill was in jeopardy until Gov. Brian Kemp helped broker a deal between House and Senate leaders who had struggled to strike a balance between providing access to legitimate patients while preventing illegal marijuana distribution. The measure now goes to Kemp for his signature or veto.

The House passed the bill 147-16, and the Senate approved it 34-20.

“Over the years, I’ve met with children who are battling chronic, debilitating diseases. I’ve heard from parents who are struggling with access and losing hope,” Kemp said. “This compromise legislation is carefully crafted to provide access to medical cannabis oil to those in need. This is simply the right thing to do.”

Georgia legalized medical marijuana consumption in 2015 for patients suffering from severe seizures, deadly cancers and other illnesses, but the government didn't provide any way for them to purchase it. It remains against the law to buy, sell or transport medical marijuana oil.

Patients obtained the drug through the mail, by driving out-of-state or from friends.

Under the bill, up to six private companies would be licensed to grow and manufacture medical marijuana oil. In addition, two universities could start medical marijuana programs. Pharmacies would initially be able to sell the drug, and a state oversight board would have the authority to allow private dispensaries.

Smoking or eating marijuana would remain prohibited.

Live: Use AJC tracker to follow Georgia bills

"For the last five years, our patients in this state have been traveling out of state. They've been breaking federal law," said state Rep. Micah Gravley, a Republican from Douglasville. "The compromise we have reaches the goal of getting safe access for the citizens in this state."

Opponents of the proposal said they worried it sets up a distribution network that could lead to the legalization of marijuana for recreational purposes.

"Many people recognize this for what it is. This is the first step toward the commercialization of recreational marijuana," said Senate Regulated Industries Chairman Bill Cowsert, a Republican from Athens. "This is the step where you open the floodgates and you are creating the infrastructure for this industry."

HB 324 would make Georgia the 34th state to allow some form of marijuana cultivation.