The Constitutional Court ruling put South Africa on course to become at least the world's fifth country to permit same-sex marriage.
It will also be the first country in Africa to do so, a continent where homosexuality is largely taboo.
In a ruling delivered by the constitutional court, Justice Albie Sachs said: "The common law definition of marriage is declared to be inconsistent with the constitution and invalid to the extent that it does not permit same-sex couples to enjoy the status and benefits it accords heterosexual couples."
The decision followed a Supreme Court of Appeal ruling in November 2004 that said same-sex couples could get married following an application by lesbian couple Marie Fourie and Cecilia Bonthuys.
That ruling requested that the courts change the common-law definition of marriage from being a "union between a man and a woman" to a "union between two persons".
"It's a bit disappointing. It feels like it's one step forward and still another one step backwards"
Keketso Maema, lawyer for Lesbian and Gay Equality project
But in its ruling on Thursday, the constitutional court judge said it was up to parliament to make the necessary changes.
Only one of the court's 11 judges dissented from the ruling,
arguing the court should have legalised gay marriage with
The court said that if parliament did not act the legal definition of marriage would be automatically changed to include same-sex unions.
That would put South Africa alongside Belgium, the Netherlands, Spain and Canada in allowing gay marriages.
Church leaders had have argued against the move, saying it
flouted public opinion in the mainly Christian country, and
called for a referendum on the divisive issue.
Meanwhile lawyers for gay rights groups said they were disappointed that the court did not act to make gay marriages legal immediately.
"It's a bit disappointing. It feels like it's one step forward and still another one step backwards," said Keketso Maema, a lawyer for the Lesbian and Gay Equality project.
"The good thing about this judgment is if parliament doesn't
do anything in 12 months the word 'spouse' would be read into the marriage act. That gets us somewhere."