Crowds of supporters cheered, hugged and wept as the court said current laws preventing the practice "violated" the constitution's guarantees of freedom of marriage and equality.
It gave the government two years to implement the ruling.
Momentum has been growing behind the push for equal marriage rights, with Taiwan's president Tsai Ing-wen openly supporting the campaign.
But there has also been anger among conservative groups, who have staged mass rallies against any change in the law.
The constitutional court said if parliament does not make the change within two years, same-sex couples could register to marry regardless, based on its interpretation.
Currently Taiwan's Civil Code stipulates an agreement to marry can only be made between a man and a woman.
"The current provisions of the marriage chapter do not allow two persons of the same sex to create a permanent union of an intimate and exclusive nature for the committed purpose of managing a life together. This is obviously a gross legislative flaw," the court said in a statement.
The decision to allow gay marriage would bolster social stability and protect "human dignity" it added.
Hundreds of gay marriage supporters gathered outside parliament in central Taipei erupted at the news, some breaking down in tears.
For Taiwan's pioneering gay rights campaigner, Chi Chia-wei, one of the petitioners who brought the case to the constitutional court, it was the culmination of 30 years of activism.
"I'm leaping with joy like a bird," Chi, 59, told AFP.
"I hope parliament will prioritise the bill instead of dragging it on for another two years," he added.
The other petitioner was the Taipei city government, which has been rejecting marriage applications by same-sex couples and was seeking clarification of the law.
At the rally, Uther Wu, 40, said the ruling was "like a cloud being blown away".
Others felt it would put Taiwan on the map.
"This will open doors for a lot of other countries in the region," said Toby Chang, 28, at the rally.
"It's also good for Taiwan. It will bring a lot of international attention and recognition," he added.
Fears of delay
President Tsai's Democratic Progressive Party, which holds a majority in parliament, backed the ruling.
"The party is happy to see and affirm the results of the grand justices' constitutional interpretation to guarantee and legalise same-sex marriage," it said in a statement.
However, some campaigners fear opposing voices in parliament may try to delay the process of changing the law.
Outside Taipei's main judicial headquarters, angry anti-gay marriage protesters beat drums shouting "unfair justice" and "sinners".
"The system of a husband and a wife is not unconstitutional," said demonstrator Becky Huang.
"The welfare of the majority should not be sacrificed to please a few people."
A panel of 14 grand justices made the ruling -- a majority of 10 was needed. Only two judges dissented.
The court said the physical and psychological need for permanent unions was "equally essential to homosexuals and heterosexuals, given the importance of the freedom of marriage to the sound development of personality and safeguarding of human dignity".
It also pointed out that attempts in parliament to legalise gay marriage have stalled in the past 10 years, affecting people's fundamental rights.
Proposals to amend the Civil Code finally passed their first reading in December, but have not progressed further.
Rights group Amnesty International urged the government to act quickly on the ruling.
"As today's ruling makes clear, whoever you love, everyone is entitled to the same human rights and equal protection under the law," it said.
(This story has not been edited by NDTV staff and is auto-generated from a syndicated feed.)