The federal government introduced a bill Friday that declares

 to close a legal loophole that could have undermined thousands of gay marriages around the world.

The bill, called an act to amend the Civil Marriage Act, says it establishes a "new divorce process that allows a Canadian court to grant a divorce to non-resident spouses who reside in a state where a divorce cannot be granted to them because that state does not recognize the validity of their marriage."

The proposed changes were prompted by a divorce case in Ontario involving a gay couple.

Legal documents filed by the federal government in the case had argued that even though the couple married in Canada, they couldn't be considered legally married because it wasn't recognized in their U.S. and United Kingdom homes.

Gay rights activists and opposition politicians accused the Tories of trying to rewrite the rules on same-sex marriage to suit their own agenda.

But the government says its opinion is that the marriages were valid and it doesn't want to reopen the debate on the definition of marriage.

"Recently it came to light that there was an anomaly in our civil marriage laws," Justice Minister Rob Nicholson said in a statement after the bill was introduced in the House of Commons. "We are fixing the anomaly in the law."

With files from Canadian Press