Spain's Senate has rejected a bill on gay marriage but MPs are likely to make it law when it returns to the lower chamber of parliament next week.
Opinion polls suggest the bill has public support in Spain
The upper house voted 131 to 119 to throw out the bill, condemned by Spain's dominant Roman Catholic Church.
However, Congress has already backed the legislation and is expected to push it through next week.
Belgium and the Netherlands are the only EU states to have legalised gay marriage to date.
Members of the Catalan Christian Democrats joined the conservative opposition Popular Party (PP) in opposing the bill.
Their political groups ranked amongst tens of thousands, including nuns and bishops, who demonstrated against the measure in Madrid on Saturday.
They say it puts same-sex and heterosexual marriages on exactly the same legal footing, including the right to adopt children.
Ahead of Wednesday's vote, the PP had to apologise for comments by a guest speaker who said homosexuality was a "pathology".
Aquilino Polaino, professor of psychiatry at Madrid's Catholic University, told the Senate that homosexuality was caused by a "violent, hostile, distant or alcoholic father" or "a cold, over-protective mother".
PP group leader Pio Garcia-Escudero apologised, saying he regretted any offence caused.
The ruling Socialist Party described Mr Polaino's views as "grotesque and Palaeolithic".
Opinion polls suggest that a majority of Spaniards support the gay marriage and adoption bill.
However, the move has met resistance in the predominantly Roman Catholic nation, with several Spanish mayors saying that they will refuse to marry same-sex couples if the bill becomes law.