* Ruling comes after seven years
* Same-sex marriage challenged by conservatives
* More than 21,000 same-sex couples married in Spain
Spain's highest court upheld the country's gay marriage law on Tuesday, rejecting an appeal lodged by the ruling People's Party seven years ago and confirming the legality of same-sex unions.
By the end of last year, more than 21,000 same-sex couples had tied the knot since Spain became the fourth country in the world to legalise gay marriage in July 2005.
Eight of the Constitutional Court's 11 judges voted in favour of the law, the court said in a statement, adding that the full ruling will be published in the next few days.
Justice Minister Alberto Ruiz-Gallardon said the government would respect the decision and leave the law as it stands.
"We're very, very pleased and particularly that the decision was 8-3 and not a close 6-5," Jesus Generelo, general secretary of the National Federation of Lesbians, Gays, Transsexuals and Bisexuals (FELGTB), said.
"I think it is clear that gay marriage is now a part of our society."
The law, introduced by the former government of Socialist Prime Minister Jose Luis Rodriguez Zapatero, was challenged in court by the People's Party (PP).
Hundreds of thousands of people marched in the streets during the Zapatero years against Socialist laws permitting gay marriage and liberalising abortion, but surveys have shown a majority of Spaniards support allowing same-sex couples equal marriage rights with heterosexual couples.
The Roman Catholic church also strongly opposed the law and priests were active in calling on people to support the anti-same-sex protests during the Zapatero years.
Conservative and Catholic groups criticised Tuesday's court ruling. The Family Forum, which organised protests against same-sex marriage, demanded the government repeal the law.
"If the PP hides behind this sentence to now accept the Zapatero law, it will be reneging on the public commitments it made in 2004 and 2005 and failing to defend the ideas of its core supporters in a politically cowardly way," it said.
Another conservative group, Hazteoir.org, said: "Making marriage the same as other types of union is a direct attack on the Spanish family".
"This equal status, as well as the promotion of divorce, will cause damage to society in the short-term," the group's head, Ignacio Arsuaga, said.
Spain's law was seen as pioneering by gay rights campaigners since it gave same-sex couples the same rights as heterosexuals, including the option of adopting children.
Many analysts thought it would be difficult for the government of conservative Mariano Rajoy to reverse the law, which would have left gay families in legal limbo.
Although some PP mayors have defied the law, refusing to marry gay couples, others support it, including Justice Minister Gallardon when he served as mayor of Madrid.