The ruling did not approve the sale or commercial production of marijuana nor does it imply a general legalization. But if the court rules the same way on five similar petitions, it would then establish the precedent to change the law and allow general recreational use.

A similar process led to the court's recent ruling that Mexican laws prohibiting same-sex marriage are unconstitutional.

"No one has said at all that marijuana is harmless. It is a drug and, as such, it causes damage," said Justice Arturo Zaldivar, who wrote the majority opinion. "What is being resolved here is that total prohibition is a disproportionate measure."

At the same time, the ruling will help legalization measures being written in Congress, said Moy Schwartzman, one of the lawyers for the plaintiffs.

"They're noting this case and using it in their favor to present a law that will be in agreement and will protect people's rights," Schwartzman said. "In Mexico, this is a political theme. But the ruling gives importance to human rights, in this case liberty."

President Enrique Pena Nieto, via his Twitter account, said he recognizes and will respect the ruling, adding that he has given his government orders to explain to Mexicans the scope of the ruling.

"This will open up the debate over the best regulation for inhibiting drug consumption, a public health issue," he wrote. "Mexico has promoted in international forums ... broadening the discussion."

Justice Zaldivar said Wednesday's ruling would forbid smoking marijuana in front of others without their consent. It is unclear whether public consumption, even by the few people covered by the case, could still be regulated under public nuisance codes as alcohol is. For example, drinking in the street is forbidden in many parts of Mexico.

"We have to see what limits will be," said Health Secretary Mercedes Juan, referring to maximum allowed quantities and where or how consumption would be allowed.

Proponents of legalizing marijuana staged a low-key demonstration outside the court building, including displaying information on marijuana use and legalization. Many in the crowd celebrated by lighting up, including Cesar Zanabria, who puffed on a fat homemade marijuana cigarette.

"Effectively this says a person can consume marijuana, or not, and no one is going to make him a criminal," Zanabria said, adding that he has been detained twice for smoking, even though personal consumption already is legal in Mexico. "This will start to get rid of the stigma."

An October opinion survey by the Parametria polling firm said that 77 percent of Mexicans opposed legalizing marijuana, while 20 percent supported the idea. The poll had a margin of error of four percentage points.

In the United States, the states of Washington, Colorado, Alaska, and Oregon have legalized marijuana use. The South American nation of Uruguay adopted a plan to create a legal pot market in 2013.