The Canadian government is abruptly arguing that the same-sex marriages of many foreigners who wed in Canada are not valid, a move that stunned the gay community and could affect thousands of couples.

In 2005, Canada became one of the first nations in the world to formally legalize gay marriage. Same-sex couples have been marrying in their thousands in Canada, and lenient rules on residency requirements for those seeking a marriage license mean many of them are from abroad.

Ottawa now says many, if not all, the unions involving foreign residents are invalid. It made the argument in a case where two women, one from England and the other from Florida, sought a divorce after their 2005 Canadian marriage.

The government's position has prompted sharp questions about why Ottawa allowed so many foreign same-sex couples to get married for so long before deciding the unions were not valid.

(This) is about to, if it hasn't already, make us look like fools on the international stage, said Martha McCarthy, a lawyer for the couple at the center of the furor.

We're the leaders of gay marriage ... and the federal government is saying 'Oh, yes, sorry, we forgot to mention that for the last nine years we've been marrying people that we didn't think those were valid', she told Reuters on Thursday.

Critics blamed the right-of-center Conservative government, which they say wants to roll back social rights such as gay marriage and abortion.

Prime Minister Stephen Harper said he was unaware of the case. Justice Minister Rob Nicholson said in a statement he would be looking at options to clarify the law so that marriages performed in Canada can be undone in Canada.

He gave no further details and did not make clear whether Ottawa would continue to argue that marriages that had already taken place could not be ended in Canada.

Activists estimate that around 7,500 same-sex couples have married in Canada since 2003, when some provinces first allowed gay marriages. About 2,500 involved were foreigners, many from countries and U.S. states that do not recognize gay unions.

Ottawa says the 2005 marriage in the latest case was not legally valid under Canadian law because the women could not have lawfully wed in England or Florida. It also cited the Canada Divorce Act, which says any couple seeking to end a marriage in Canada must have lived there for a year.

McCarthy said her clients' message was: We can't get divorced in our own jurisdictions because they don't recognize the validity of our marriage. You guys here in Canada married us so please give us a divorce because no one else will.

A Toronto judge will hear the case on February 27 and 28 and decide whether the government's argument is valid, although the loser is bound to appeal any ruling.

The gay marriage surge was a boon for the tourist industry, which quickly offered wedding packages to U.S. couples.

Evan Wolfson, president of New-York-based gay rights group Freedom to Marry, said it would be extreme, absurd and cruel to now declare the Canadian marriages invalid.

This will come as giant shock not only to the couples but to the businesses, employers, banks and others who deal with them so hopefully they're going to walk back this preposterous undermining of families, he told Reuters.

The issue could become a political problem for Harper, who said he had no intention of reopening the gay marriage file. 

Nick Bala, a professor and family law expert at Queen's University, said the case underlined existing problems with the way gay marriage works in Canada.

There are good reasons why Canadian family courts are only going to take jurisdiction over relationships that have a significant (link) to Canada, he told Reuters.

Foreign gays who only came to Canada to marry and then returned to seek a divorce could have major problems if child custody were an issue, and there was little logic in asking Canadian courts to make decisions about children living elsewhere, he said.

There are good reasons for Canada to be a marriage haven for same-sex couples. It's not clear that it should be a divorce haven for same-sex couples, Bala said.