The decision is a defeat for medical marijuana advocates who had lobbied successfully in 10 states to allow marijuana use for medical reasons.
Justice John Paul Stevens, writing the 6-3 decision, said that Congress could change the law to allow medical use of marijuana.
The closely watched case was an appeal by the Bush administration in a case that it lost in late 2003. At issue was whether the prosecution of medical marijuana users under the federal Controlled Substances Act was constitutional.
The ruling is a serious setback not only for proponents of medical marijuana who say it is helpful for serious and chronic pain, but also for states' rights, reports CBS News Correspondent Bob Fuss.
Ten states have legalized medicinal marijuana — eight by direct votes of the people — but the federal government arrests and prosecutes patients who use it and the Supreme Court has now ruled they can continue to do so, reports Fuss.
Under the Constitution, Congress may pass laws regulating a state's economic activity so long as it involves "interstate commerce" that crosses state borders. The California marijuana in question was homegrown, distributed to patients without charge and without crossing state lines.
Stevens said there are other legal options for patients, "but perhaps even more important than these legal avenues is the democratic process, in which the voices of voters allied with these respondents may one day be heard in the halls of Congress."
California's medical marijuana law, passed by voters in 1996, allows people to grow, smoke or obtain marijuana for medical needs with a doctor's recommendation. Alaska, Colorado, Hawaii, Maine, Montana, Nevada, Oregon, Vermont and Washington state have laws similar to California.
In those states, doctors generally can give written or oral recommendations on marijuana to patients with cancer, HIV and other serious illnesses.
In a dissent, Justice Sandra Day O'Connor said that states should be allowed to set their own rules.
"The states' core police powers have always included authority to define criminal law and to protect the health, safety, and welfare of their citizens," said O'Connor, who was joined by other states' rights advocates.
The legal question presented a dilemma for the court's conservatives, who have pushed to broaden states' rights in recent years, invalidating federal laws dealing with gun possession near schools and violence against women on the grounds the activity was too local to justify federal intrusion.
O'Connor said she would have opposed California's medical marijuana law if she was a voter or a legislator. But she said the court was overreaching to endorse "making it a federal crime to grow small amounts of marijuana in one's own home for one's own medicinal use."
The case concerned two seriously ill California women, Angel Raich and Diane Monson. The two had sued then-U.S. Attorney General John Ashcroft, asking for a court order letting them smoke, grow or obtain marijuana without fear of arrest, home raids or other intrusion by federal authorities.
Raich, an Oakland woman suffering from ailments including scoliosis, a brain tumor, chronic nausea, fatigue and pain, smokes marijuana every few hours. She said she was partly paralyzed until she started smoking pot. Monson, an accountant who lives near Oroville, California, has degenerative spine disease and grows her own marijuana plants in her backyard.
In the court's main decision, Stevens raised concerns about abuse of marijuana laws. "Our cases have taught us that there are some unscrupulous physicians who overprescribe when it is sufficiently profitable to do so," he said.
In other Supreme Court rulings:
The narrow 5-4 decision is a victory for disabled rights advocates, who said inadequate ship facilities inhibited their right to "participate fully in society."