The vote at the Nine-Member Constitutional Court came as they ruled on the lawsuits by two same-sex couples that wanted to get married.
Five voted in favor, arguing all people were equal.
Four said the issue had to be debated in parliament.
In Latin America, Argentina, Brazil, Colombia and Uruguay have already legalised same-sex marriage.
The ruling in Ecuador follows a decision by the Inter-American Court on human rights which said countries should give same-sex couples the right to marry and comes as other countries in the region debate changing their laws.
Celebrations erupted in Quito and in Guayaquil, Ecuador’s second-largest city, after the decision was announced.