The Western Cape High Court sensationally ruled that dagga should be legalised for home use in 2017.
South Africans have celebrated the ruling by their constitutional court and are getting ready to grow some dagga, as they call it.
The state appealed to the Constitutional Court, which upheld the high court's findings.
South Africa's government had opposed its legalisation, arguing the drug was "harmful" to people's health.
The Constitutional Court has delivered a landmark ruling in which it decriminalises the private use of dagga.
Cannabis is referred to as "dagga" in South Africa.
Deputy Chief Justice Raymond Zondo ruled that the right to privacy should not be limited to the home or private dwelling and should be extended to any private space.More news: The Patriots Have Agreed To A Trade For Browns Receiver Josh Gordon
More news: Trump Continues to Deny Puerto Rico Death Toll Despite Backlash
More news: Hurricane turns deadly, floods Carolinas
The ruling comes after parliament banned the cultivation of weed for private use, sparking street protests and a court case.
While illegal, marijuana is an important cash crop for rural communities, particularly in the Eastern Cape and KwaZulu-Natal provinces. In addition to this, parliament has been given two years to change sections of both the drug trafficking act and the medicine controls act.
Previously, possessing, growing or using marijuana for personal use - even in small quantities - exposed users to fines of up to hundreds of dollars (euros) as well as jail time, although this latter punishment was rare.
Parliament would have to decide on this, it said.
"Davis' order had confined the declaration of invalidity to private adult use at home, while the Constitutional Court did not limit it to use at home".
In April Zimbabwe became the second country in Africa, after Lesotho, to legalise the use of marijuana for medical use.