The Republican-led House of Representatives passed the measure late on Thursday as part of a larger bipartisan funding bill. The measure still needs approval in the Democrat-controlled Senate, and then to be signed into law by President Barack Obama.
Representative Dana Rohrabacher, a California Republican who offered the amendment, called its passage "a victory for states' rights, for the doctor-patient relationship, for compassion, for fiscal responsibility."
It seeks to "prohibit the use of funds to prevent certain states from implementing their own state laws that authorize the use, distribution, possession, or cultivation of medical marijuana," according to the amendment, which passed by a 219-189 vote.
Minnesota this week became the latest of the more than 20 states to put in place laws permitting marijuana use to treat conditions such as cancer and epilepsy.
"Federal tax dollars will no longer be wasted arresting seriously ill medical marijuana patients and those who provide to them," said Dan Riffle, federal policy director for the Marijuana Policy Project, a group that backs wider marijuana use.
Polls show a growing number of Americans accept wider use of the drug, while states also see it an a potential new source of tax and other revenue to fill coffers drained by the recent economic slowdown.
But some state governors and others see legalizing marijuana as taking its acceptance a step too far. Some critics also worry that marijuana's wider use is outpacing the regulations needed to control it.
Thursday's amendment is part of a larger bill to fund the Department of Justice next fiscal year, but must still be squared with the Senate's version of the spending bill.
While the federal government still classifies marijuana as an illegal narcotic, the Obama administration has signaled willingness to allow looser enforcement, including encouraging banks to support state-licensed suppliers.
"This is a historic vote, and it's yet another sign that our federal government is shifting toward a more sensible marijuana policy," the Marijuana Policy Project's Riffle said.