Chile approved marriage equality legislation in a landslide vote on Tuesday, after four years of inaction.

Both houses of Chile's Congress authorized the measure with overwhelming majorities, making it the eighth Latin American country to allow same sex marriage, as well as the 31st worldwide.

President Sebastián Piñera, who is poised to leave office in March, opposed the legislation for years. But just six months ago, the conservative leader indicated he'd changed his position on the issue paving the way for Congress to act. He is is expected to sign it into law.

"I think the time has come to guarantee that freedom and that dignity to all people," Piñera said in an annual speech to Congress on June 1.

"I think the time has come for marriage equality in our country," he added.

Existing laws allow gay couples to unite under a Civil Union Pact, which was approved in 2015 and gives couples many of the same rights as married but denies them the right to adopt.

The new law will extend full parental rights to same sex parents and expand spousal benefits and adoption rights for married same-sex couples.

Piñera's public change of heart prompted the bill's recent expedited push through the legislature after it languished in both houses of Congress for four years. It was first introduced in 2017 by then-President Michelle Bachelet.

Rights activists spent more than a decade campaigning for the change, including MOVILH, one of the major backers of the bill.

"After centuries of abuse," the LGBTQ rights group said in a tweet, "the doors of justice, equality and dignity have opened to same sex couples."

The move comes less than two weeks ahead of a polarizing election — a run-off- in which Chileans must decide whether to replace Piñera with far-right populist Jose Antonio Kast or Gabriel Boric, a young leftist former student leader.

On Tuesday Kast, a Catholic who does not support gay marriage and has opposed the measure in the past, revealed that he would have signed the bill into law anyway if he had been president, Reuters reported.

Copyright 2021 NPR. To see more, visit https://www.npr.org.