Organisers describe ban as a “flagrant violation of the constitution” and say they will take legal action.
Twelve of 14 judges in the court, known as the Judicial Yuan, said current marriage laws violate the constitutional rights of same-sex couples.
It gave Taiwan’s government two years to implement the ruling.
Video posted to social media showed crowds cheering and waving rainbow flags outside parliament in Taipei after the announcement was made.
Activists were already optimistic the decision would go in their favour.
But conservative groups had staged mass rallies against a change in the law.
— Ministry of Culture 🇹🇼 (@CulturalTaiwan) May 24, 2017
At the heart of the case was a clause in Taiwan’s Civil Code that an agreement to marry should be made between a man and a woman.
This “violated” the constitution’s guarantees of freedom of marriage and people’s equality, the court said.
Chi Chia-wei, a 59-year-old gay rights campaigner who brought the case to the constitutional court, had urged judges to allow same-sex couples to register to marry the next day if they approved the change.
The Taipei city government, which also launched a case, had been rejecting marriage applications by same-sex couples and was seeking clarification of the law.
Al Jazeera’s Adrian Brown, reporting from Taipei, said: “Taiwan has in a sense become a beacon of gay rights.”
He added that conservatives were likely to protest against the proposed change of law over the next two years and to call for a referendum.
“They are angry and disappointed,” Brown said. “They say it’s time for all Taiwanese people to have their say in this debate, and claim a cultural convention is under attack.”
Lawyer Huang Di-ying said the court’s decision was “historic”.
“It will be a barometer of human rights protection in the region as Asia follows the United States’ and Europe’s steps to recognise same-sex marriages,” he said.
Momentum for same-sex marriage had been gathering since President Tsai Ing-wen, Taiwan’s first female leader who supported the change of law, came to power last May.
“Family conflicts will increase and the whole definition of marriage will be changed,” said Andrew Chang, spokesman for the Alliance of Religious Groups for the Love of Families Taiwan, an anti-gay marriage group.
“Ancestral lineage and family structure will all be disrupted,” he added, saying he believed having sex with someone of the same gender was “unnatural and harmful”.