South Africa's Deputy President Phumzile Mlambo-Ngcuka has signed the Civil Union Act which gives same-sex couples the right to marry.
South Africa is the first African country to approve such unions
South Africa will be the first African country where gay people can wed when the law comes into force on Friday.
The law was approved by MPs two weeks ago despite objections from religious groups and traditional leaders.
The Constitutional Court ruled last year that the existing laws discriminated against homosexuals.
The Civil Union Act gives gay people the same rights as heterosexual couples.
The ruling was based on the constitution, which was the first in the world specifically to outlaw discrimination on the grounds of sexual orientation.
This is unusual in Africa where homosexuality is largely taboo - notably in its neighbour Zimbabwe.
Reuters news agency reports that religious groups had mounted a last-ditch effort to block the new marriage law, demanding a referendum on the issue.
"To force the morality of the radical homosexual minority on the people of South Africa through law is, in effect, to lead the masses astray," the Christian Action Network said in a statement.
But gay activists have welcomed the law.
"We are very happy. We welcome the political commitment shown by the country's leaders," said Fikile Vilakazi spokeswoman for the Joint Working Group, a network gay organisations, AFP news agency reports.
"It is an historic decision in terms of the African continent."
During the parliamentary debate earlier this month, Home Affairs Minister Nosiviwe Mapisa-Nqakula told MPs: "In breaking with our past... we need to fight and resist all forms of discrimination and prejudice, including homophobia."
Are you planning to marry under the new Civil Union Act when into comes into law on Friday? Use the form below to let us know if you want to share your experiences.
The BBC may edit your comments and not all emails will be published. Your comments may be published on any BBC media worldwide.