HARRISBURG - The House voted Wednesday to legalize medical marijuana, ending a debate that languished for years and all but ensuring that Pennsylvania will become the 24th state to pass such a law.

The measure will allow people suffering from cancer, epilepsy, multiple sclerosis, intractable seizures, and other conditions to access medical marijuana in pill, oil, or ointment form at dispensaries statewide. It would not be able to be smoked.

The bill now heads to the Senate, where it has had support and leaders say it will pass. Gov. Wolf, a Democrat, has pledged to sign it.

Until Wednesday, the House had been the legislation's biggest roadblock. To the end, advocates on both sides pressed their case, at times in personal terms.

"We have a chance today to improve the lives of kids - and old people like me," said Rep. Jeff Pyle (R., Armstrong), who choked back tears as he described his own cancer battle.

Before the 149-43 vote, opponents renewed their arguments - that marijuana has not been approved for medicinal purposes by the U.S. Food and Drug Administration, or that this step could open the door to ultimately legalizing recreational use of pot in the state.

"This is a dangerous drug," said Rep. Jerry Knowles (R., Schuylkill). "This is a gateway drug."

The bill lays out regulatory steps. Dispensaries, as well as those who grow and process medical cannabis, will have to be licensed by the state. Doctors prescribing the treatment will have to register as practitioners. The ID cards given to patients to access the medicine will have to be renewed annually.

The bill would permit 25 growers or processors statewide, each paying a $200,000 registration fee and yearly renewal fees. As many as 50 dispensaries could be established, each with up to three locations and paying initial registration fees of $30,000.

Officials said it could be a year or more before a program is up and running. The legislation calls for an advisory board to first be established within the Department of Health.

Twenty-three other states, including New Jersey, have enacted similar laws, following a wave of public sentiment that the benefits of legalizing the drug, if properly regulated, can outweigh the drawbacks.

Said Rep. Michael O'Brien (D., Phila.): "Put aside philosophy, put aside agendas, and think for a moment of giving a moment of relief to the afflicted."

Wolf hailed the vote. "We will finally provide the essential help needed by patients suffering from seizures, cancer, and other illnesses," he said in a statement.

Twice in the last two years, the Republican-controlled Senate had passed a version of the bill. But supporters could not overcome opposition in the GOP-led House. Former Gov. Tom Corbett, a Republican, was also slow to back the legislation.

Wolf and legislators credited the turnaround to legions of citizens who kept up the fight. Many were parents whose children are chronically ill or suffer seizures that they say diminished or disappeared entirely under cannabis treatment.

"You all have shown, by the way you've done this, that our democratic system can work," the governor told a group of advocates this week when lawmakers signaled they would consider the bill. "You have done a phenomenal job of making a really important case to the people in this building that this is an important issue. This did not happen by accident."

For Jeffrey Fogel, a physician from Ambler who suffers from a chronically painful neurological disease, the timing of Wednesday's vote was significant. The U.S. Centers for Disease Control and Prevention came out with recommendations this week that doctors limit prescribing opioids for pain.

"But they don't leave chronic-pain patients like myself with any option," Fogel said. That is where he hopes marijuana can help.

Fogel, 62, has tried cannabis twice, from a friend in New Jersey. In 15 minutes, he said, the drug took him from "riding the worst pain possible" to feeling OK. That was when he became an advocate.

He pushed to keep "chronic pain" as a category in the bill so that those who suffer from it could access the drug. He also submitted testimony to House committees studying the issue.

"Anybody who's experienced chronic pain knows that if there's anything that works that has less side effects than what's currently out there, they're in favor of it," he said.