Costa Rica's Supreme Court has struck down the nation's ban on same-sex marriage, ruling it unconstitutional and discriminatory.

The court gave legislators 18 months to change the law.

President Carlos Alvarado Quesada welcomed the ruling, saying that he wants to guarantee “no person will face discrimination for their sexual orientation.”

(Related: Costa Ricans reject presidential candidate who opposed same-sex marriage.)

Costa Rica is among the 23 countries to adopt the American Convention of Human Rights, also known as the Pact of San Jose. In January, the Inter-American Court of Human Rights, which oversees compliance with the convention, said that member countries had to extend marriage rights to gay and lesbian couples.

At a press conference held on Wednesday, Supreme Court judge Fernando Castillo cited the opinion, saying that Costa Rica's laws were inconsistent with the convention. He also said that if lawmakers do not change the nation's marriage laws to include gay couples, then the ban will end on its own.

Roughly a quarter of legislators are evangelical.

Enrique Sanchez, Costa Rica's first openly gay legislator, told the AFP that he does not believe the assembly will comply with the court's request.