Chile's Congress approved a bill aimed at legalizing same-sex marriage on Tuesday. The bill was approved through a landslide vote that will clear the way for it to eventually become law.

After four years of inactivity, both houses of Chile's Congress voted in an overwhelming majority to approve the bill. If signed into law, Chile would become the eighth Latin American country to legalize same-sex marriage. It would also become the 31st country in the world to pass such legislation.

Latin American countries that currently recognize same-sex marriages include Argentina, Brazil, Chile, Colombia, Costa Rica, Ecuador, Uruguay, and parts of Mexico.

The law was passed by the Chamber of Deputies, the lower house of Congress, with 82 votes in favor, 20 votes against, and two abstentions. Chile's Senate has previously voted in favor of the law.

President Sebastián Piñera, who is set to leave office in March next year, has long opposed the bill. However, just six months ago, the conservative leader stated that he had changed his mind about the subject, allowing Congress to act. It is expected that he will sign the approved bill into law.

In June, Piñera said that he wanted to guarantee freedom and dignity to all people. He added that the time was now right to ensure marriage equality for all citizens of Chile.

While same-sex marriage is still illegal in Chila, same-sex couples can be recognized as being together under the country's Civil Union Pact. Under the law, which was approved in 2015, same-sex couples are given the same rights as married couples, except for the right to adopt.

The new bill aims to extend full parental rights to same-sex couples and expand their benefits to become in line with other married partners. The bill was initially introduced in 2017 by former president Michelle Bachelet. Since it was proposed, the bill has been in limbo in both houses of Congress.

LGBTQ rights groups have spent years campaigning for change in Chile, with groups calling on the government to approve the long-awaited bill.

The announcement comes less than two weeks before a decisive election in which Chileans must choose between far-right candidate Jose Antonio Kast and leftist former student leader Gabriel Boric.

Kast, a Catholic who opposes homosexual marriage and has previously opposed the bill, stated on Tuesday that if he had been president, he would have signed it into law nonetheless.