The court, which voted on the measure on Wednesday night, said that the laws were discriminatory and must be immediately changed.
Magistrate Fernando Castillo told reporters that the ban was inconsistent with an opinion issued in January by the Inter-American Court of Human Rights that said homosexual couples must have the same rights to marry as heterosexual couples.
Read more: Germans celebrate first gay marriages
The Supreme Court gave Costa Rican lawmakers 18 months to implement laws lifting the ban. Should they fail to meet the deadline, gay marriage will automatically become legal.
Evangelicals push back against orderCosta Rica's President Carlos Alvarado welcomed the Supreme Court's order.
"We continue to deploy actions that guarantee no person will face discrimination for their sexual orientation or gender identity, and that the state's protection be given to all families under equal conditions," he wrote on Twitter.
Enrique Sanchez, the country's first openly gay member of the legislature, said he thinks lawmakers won't be able to agree on a new law within the next year and a half.
"What I see happening is that the norm [the gay-marriage ban] will simply be declared unconstitutional in 18 months' time," Sanchez said.
The court ruling didn't sit well with some evangelical politicians, with lawmaker Jonathan Prendas saying that the court's decision "put a gun to our head" to change the law.
Costa Rica, which has a strong Catholic tradition, has seen a rise in evangelical churches in recent decades. Evangelical lawmakers currently fill 14 of the Legislative Assembly's 57 seats. Gay marriage was a highly contested issue during the country's presidential election in April this year.
rs/rt (AP, AFP)
Every evening at 1830 UTC, DW's editors send out a selection of the day's hard news and quality feature journalism. You can sign up to receive it directly here.