Pro-marijuana activists cheered the decision in the public gallery of the Constitutional Court when the landmark ruling was announced: "Weed are free now!"
The unanimous ruling by the judges also legalized the cultivation of cannabis for private consumption, reported the BBC. The ruling does not legalize the sale or public consumption of pot, however.
In his decision, Deputy Chief Justice Raymond Zondo ruled that the private possession and use of cannabis are protected by the South African constitution.
“It will not be a criminal offense for an adult person to use or be in possession of cannabis in private for his or her personal consumption,” Zondo said.
Up to now, South Africa's government had opposed legalization, arguing that cannabis was "harmful" to people's health.
The government has not yet commented on the ruling, which is binding.
The Cannabis Development Council of South Africa welcomed the ruling, and appealed to the government to drop charges against people previously found in possession of cannabis, or dagga, as it is called in South Africa.
Three cannabis users who had faced prosecution for using the drug brought the case, saying the ban “intrudes unjustifiably into their private spheres.”
Jeremy Acton, the leader of the Dagga Party, which campaigns for the use of cannabis, said the ruling should have gone further to legalize the carrying of marijuana in public.