The High Court in Pretoria allowed for 65-year-old Robin Stransham-Ford to have a doctor help him end his life, and for the doctor to be protected from prosecution.
Medically-assisted suicide remains illegal in South Africa, but there have been growing calls for it to be legalised.
Judge Hans Fabricius said in his ruling that Stransham-Ford was entitled "to end his life, either by administration of a lethal agent or by providing the applicant with the necessary lethal agent to administer himself."
It said it expected the judge's decision to "set in motion the process of legalising assisted dying in South Africa."
More From This Section
The court heard that Stransham-Ford, a retired advocate suffering from terminal prostate cancer, had a life expectancy of only a few weeks.
Assisted suicide is illegal in many parts of the world.
Switzerland is one of the few countries in Europe that allows doctors help patients end their lives.
In February, Canada's supreme court lifted a ban on doctor-assisted suicide for mentally competent adults suffering from an incurable disease.
The suicide occurred in New Zealand, where Davison was leaving. He was placed under house arrest for five months.