WASHINGTON — Libertarian-minded and moderate Republicans joined forces Friday morning with Democrats in a House vote to block the federal government from interfering with states that permit the use of medical marijuana.

The unusual coalition produced a surprising 219-189 vote in the Republican-controlled House that reflects more permissive public attitudes toward medical pot use. It ran counter to the drug’s official classification as holding “no currently accepted medical use” and a “high potential for abuse.”

Maine Reps. Chellie Pingree and Mike Michaud both voted in favor of the measure.

Friday’s vote came as the House debated a bill funding the Justice Department’s budget. Forty-nine Republicans joined all but 17 Democrats who voted in approving a provision to block the Justice Department from interfering with state laws permitting the “use, distribution, possession or cultivation of medical marijuana.”

The amendment by conservative Republican Rep. Dana Rohrabacher of California – the first state to legalize medical marijuana – came as almost half the states have legalized marijuana for medical uses, such as improving the appetites of cancer patients undergoing chemotherapy. Other states permit the use of a nonpsychoactive marijuana extract to treat epilepsy.

The measure doesn’t address the sale and use of marijuana for recreational purposes in Colorado and Washington, where voters have legalized it over objections from most elected officials.

But it comes as the public is taking an increasingly permissive view toward medical pot use, particularly to help people suffering from chronic pain and nausea.

“Public opinion is shifting,” Rohrabacher said, noting a recent Pew Research Center survey that found 61 percent of Republicans support medical marijuana. The numbers are higher for independents and Democrats.

“Despite this overwhelming shift of public opinion, the federal government continues its hard line of oppression against medical marijuana,” he said.

Rep. Earl Blumenauer, D-Ore., told opponents that “this train has already left the station.” While almost 4 out of 5 Republicans opposed the amendment, it picked up Republican supporters from libertarians like Justin Amash, R-Mich., and Thomas Massie, R-Ky., and moderates such as Fred Upton, R-Mich., and Jon Runyan, R-N.J. Democrats opposed were typically more moderate

The move by the House would wipe away the sticky issues that arise from a fundamental question associated with state-approved sales of pot: How do you legally regulate the production, distribution, sale and use of marijuana for medical purposes when federal law bans all of the above? Federal agents in recent years have raided storefront dispensaries in California and Washington, seizing cash and pot.

“This is essentially saying, ‘Look, if you are following state law … the feds just can’t come in and bust you and bust the doctors and bust the patient,” said Rep. Sam Farr, D-Calif.