Contributing to a growing drug policy debate in Latin America, the justices voted 4-1 in favour of the four members of the Mexican Society for Responsible and Tolerant Personal Use, whose Spanish acronym spells "SMART."
Justice Arturo Zaldivar, who backed the group's effort, said the country's marijuana prohibition is an "extreme" and "disproportionate" measure.
The vote allows SMART to produce and consume its own pot, but not sell it. The ruling is expected to prompt other activists to turn to the top court, which must issue five similar rulings to establish a legal precedent.
Outside the court in the capital's historic center, dozens of people celebrated the ruling by smoking joints and dancing to reggae music.
"We won!" exclaimed Francisco Torres Landa, a 50-year-old lawyer and SMART member, pumping his fist in the air inside the chamber.
His group hopes the ruling will force Congress to consider legalizing marijuana, a move they say would strip drug cartels of a key source of cash and therefore reduce the country's runaway violence.
President Enrique Pena Nieto, who has opposed the legalization of pot, said his government "respects and accepts" the ruling.
But he told reporters that the decision is limited in scope to the four members of SMART and that it does not mean a broader legalization of marijuana.
The ruling, however, "opens a broad debate" on how to regulate the use of marijuana and "inhibit its consumption," he said.
Health Minister Mercedes Juan Lopez said her ministry will now have to draft new regulations to ensure that the health of non-pot smokers and children is protected.
The government will also have to look at terms for importing seeds.
The SMART members themselves -- two lawyers, an accountant and a social activist -- say they do not even plan to grow and smoke pot.
Rather, the activists want to force the government and lawmakers to rethink the controversial war on drugs.
"This is not for the four of us," SMART member Torres Landa told AFP, saying the goal was to "break" the government's marijuana prohibition.
Pena Nieto, who took office in December 2012, has pressed on with his predecessor's controversial strategy of using troops to go after cartels.
The ruling, Pena Nieto said, "does not imply in any way the elimination of the policy that the government has maintained."
Legalization has caught on in other parts of Latin America.
Marijuana legalised in Washington state
Uruguay has created a regulated market for pot, while Chile's Congress is debating a law to legalize its recreational and medical use.
In the United States -- the biggest consumer of drugs from Mexico -- 23 US states and the capital Washington, DC now allow medical marijuana, and four others plus the US capital have legalized pot for recreational use.
The judge who voted against, Jorge Mario Pardo, argued that the ruling could not work because it does not address the ban against obtaining the seeds to grow marijuana.
"Mexico has many problems to resolve. It's not ready for this," said Consuelo Mendoza, president of the National Union of Parents, who took part in an anti-marijuana protest outside the court.
SMART took its case to the courts in 2013 after the government's health regulator, Cofepris, denied its request for permission to produce and consume its own marijuana for recreational use.
While Mexico's government has opposed the legalization of drugs, health authorities granted an exception last month for an eight-year-old girl suffering from severe epilepsy.
The girl, Grace, took her first treatment of a cannabis-based oil last month, which her parents hope will reduce the 400 epileptic fits she endures each day.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ