The constitutional court said Taiwan's current Civil Code, which stipulates an agreement to marry can only be made between a man and a woman, "violated" the constitution's guarantees of freedom of marriage and people's equality.
It gave Taiwan's government two years to implement the ruling.
If parliament does not make the change within two years, the court said same-sex couples could register to marry regardless, based on its interpretation.
"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," a statement from the court said.
The push for equal marriage rights has gathered momentum on the island with hundreds of thousands rallying in support.
But there has also been anger among conservative groups, who have staged mass protests against any change in the law.
The court ruled that the decision to allow gay marriage would contribute to social stability and protect "human dignity".
Supporters from both camps had gathered in central Taipei to await the decision, with hundreds of pro-gay marriage campaigners flying rainbow flags outside parliament.
A panel of 14 grand justices made the ruling -- a majority of 10 was needed. Only two judges dissented.