JOHANNESBURG, Nov. 14 — South Africa’s Parliament overwhelmingly voted today to legalize same-sex marriages, making the nation the first in Africa and the fifth in the world to remove legal barriers to gay and lesbian unions, according to activists.

The legislature voted after the nation’s highest court ruled that South Africa’s marriages statutes violated the constitution’s guarantee of equal rights. The court gave the government a year to amend the legal definition of marriage. That deadline expires in two weeks.

Melanie Judge, program manager for OUT, a gay rights advocacy group, noted that the Netherlands, Belgium, Spain and Canada were the only other countries to allow same-sex marriages nationwide. In most African nations, she said, homosexuality is still treated as a crime. Some penalties are stiffer than those for rape or murder..

Ms. Judge credited South Africa’s liberal constitution with forcing change.

“This has been a litmus test of our constitutional values,” she said in a telephone interview. “What does equality really mean? What does it look like? Equality does not exist on a sliding scale.”