In an 8-3 decision, the court ruled that adults would be able to apply for permits to cultivate and consume their own cannabis. Smoking in public and in front of children is banned.
The ruling does not mention the commercialisation of cannabis.
The decision came after a legalisation bill stalled in Congress.
"Today is a historic day for liberties," Supreme Court president Arturo Zaldívar said.
Health risks of recreational cannabis
Why are so many countries now saying cannabis is OK?
But some groups said the ruling was unlikely to result in major immediate changes.
Mexico United Against Crime, a non-governmental organisation, said the decision "does not decriminalise the activities necessary to carry out consumption" such as possession and transportation.
Mexico's lower house approved a bill legalising the recreational use of cannabis in March, but it still needs final approval by the Senate.
The legislation would let users with a permit carry up to 28g and grow as many as eight plants at home for personal use. At present, it is illegal to carry more than five grams.
Supporters of legalisation hope it could reduce some of the violence related to illegal drugs trade, which claims the lives of thousands of people in the country every year.