SAN JOSE, Costa Rica (AP) — Costa Rica’s supreme court has given the country’s legislature 18 months to change the law to allow gay marriage.

The court voted Wednesday night to make gay marriage legal, declaring that existing laws banning it were unconstitutional.

Magistrate Fernando Castillo said in a news conference that the laws were inconsistent with an opinion issued in January by the Inter-American Court of Human Rights. That court had said countries, such as Costa Rica, that had signed the American Convention on Human Rights had to take immediate action to legalize gay marriage.

Castillo says that if the legislature does not make the necessary changes within 18 months gay marriage will automatically become legal because the current ban will cease to exist.