JOHANNESBURG — A terminally ill man died of natural causes shortly after he was granted the right to end his life in South Africa, where euthanasia is illegal, a lobbying group said Thursday.

In a first-of-its-kind ruling for the nation, Judge Hans Fabricius said Thursday that Robin Stransham-Ford could be euthanized with no legal or professional consequences for the doctor who would participate. But Stransham-Ford died before that could happen.

“He died before the legal injection was delivered, so a peaceful, natural death,” said Sean Davison, founder of the group DignitySA.

Stransham-Ford, 65, only had weeks to live, said DignitySA, which supported his court bid and picketed outside the courthouse in the capital Pretoria. He had prostate cancer and the medication used to manage his pain left him constantly sedated, the group said.

Stransham-Ford, who was being cared for by the mother of his 12-year-old daughter, died at home in Cape Town with his family.

“I wish to end my life with dignity, surrounded by my loved ones, while I am able to breathe on my own, speak to my loved ones and see and hear them,” Stransham-Ford told Fabricius, according to a local newspaper, the Pretoria News. The Justice Department said before Stransham-Ford died that it planned to appeal Fabricius’ decision.

Willem Landman of DignitySA said the group would welcome an appeal as a chance to test the right to die against the constitution.

The law currently regards assisted suicide in the same way as homicide or murder. In his court order granting the assisted suicide, Fabricius said this limited the constitutional right to dignity.