The Spanish parliament approved a same-sex marriage law Thursday, handing a major victory to the governing Socialist Party and angering such opponents as the Roman Catholic Church, which denounced the measure as "unjust."

Spain's action follows similar moves by the Netherlands and Belgium, where same-sex marriage has been legal for some time. On Tuesday, Canada's House of Commons also passed a gay marriage bill, which now awaits Senate approval. Several European countries have sanctioned civil unions for homosexual couples.

Gay marriages will be permitted in Spain as soon as the law, which passed the Congress of Deputies in a 187 to 147 vote, is published in the official government registry, according to the parliamentary press office. The Spanish law also gives same-sex couples the right to adopt children and receive inheritances.

The vote was held after Prime Minister Jose Luis Rodriguez Zapatero unexpectedly took the floor of parliament to speak in its support. "We are expanding the opportunities for happiness of our neighbors, our colleagues, our friends and our relatives," he said. "At the same time, we are building a more decent society."

A roar of applause rippled through the visitors' galleries of the historic 19th-century chamber, and supporters who had gathered outside the building cheered after votes were cast.

Mariano Rajoy, the leader of the opposition Popular Party, who was denied the opportunity to address parliament after Zapatero's surprise appearance, accused the prime minister of dividing Spanish society.

"I have the firm conviction that if Zapatero had called together all the parties, we would have created a law that would have majority support in parliament and among Spaniards," he said.

The Popular Party, which has favored recognizing civil unions without using the word marriage, said it would consider an appeal to the Constitutional Court, Spain's highest tribunal.

Rajoy said the issue was "not a debate between Catholics and non-Catholics" in this predominantly Catholic country.

The Catholic Church has vehemently opposed same-sex marriage and divorce in Spain, taking the unusual step of endorsing a "pro-family" demonstration in Madrid on June 18. Pope Benedict XVI has condemned gay marriage as an expression of "anarchic freedom" that threatens the future of the family.

The Spanish Bishops' Conference released a statement describing Thursday's decision and a bill passed Wednesday facilitating divorce as blows to the institution of marriage. Such measures reduce marriage to "a light contract that any party can rescind by virtue of mere desire just three months after stipulating it," the statement said.

"Considering this terrible and serious situation, Spanish society must be trusted to know how to stand in defense of marriage, family and children," the bishops said. "These unjust laws must be opposed through every legitimate means that the state makes available to its citizens."

Supporters of gay marriage praised the law's passage and announced plans to celebrate in an annual gay pride parade in Madrid on Saturday.

"I traveled to Madrid to participate in Saturday's march for the first time because of what happened on the 18th," said Javier Abreu, a spokesman for the Socialist Party in Tenerife, Canary Islands. Abreu was awaiting celebrations at Chueca Plaza, the center of gay pride events here this week.

At a presentation in Madrid for his latest film, "Volver," or "Return," starring Penelope Cruz, the movie director Pedro Almodovar also expressed support. "It was about time," he said. "This law will enrich society. I think it is pro-family."

Pedro Zerolo, a gay rights activist and member of the Spanish Socialist Party, flashes a victory sign outside the parliament building in Madrid after Spain became the third country in the world, after Belgium and the Netherlands, to give gay couples the same right to marriage as heterosexuals.Critics of the law, which was denounced by the Catholic Church, hold banners reading "Marriage equals man and woman" at a Madrid rally.