The county's top court voted 8-3 to dismiss the appeal of the conservative Popular Party filed shortly after Spain became the world's third country to approve gay marriage.
Spain's Parliament passed the gay marriage law in 2005 when it was Socialist-controlled, with Popular Party deputies opposed. The Popular Party took power late last year after the Socialists were ousted over their handling of the economy.
The gay marriage law angered the predominant Roman Catholic Church but opinion surveys showed most Spaniards backed it. Belgium and the Netherlands approved gay marriage laws before Spain.
More than 22,000 gay marriages have taken place in Spain.