(A rainbow flag symbolizing gay pride hangs from the awning of a store in New York June 22, 2011/Shannon Stapleton)

When New York became the sixth and by far the largest state to legalize same-sex marriage, following a grueling overtime session in the state legislature, it immediately transformed the national debate over the issue, legal experts said.

With a population over 19 million — more than the combined population of the five states that currently allow gay marriage, plus the District of Columbia, where it is also legal — New York is poised to provide the most complete picture yet of the legal, social and economic consequences of gay marriage.

“I think that having same-sex marriage in New York will have tremendous moral and political force for the rest of the country — in part because New York is a large state, and in part because it hasn’t come easily,” said Suzanne Goldberg, a professor at Columbia Law School.

The New York Assembly passed same-sex marriage legislation twice before, in 2007 and 2009, but in both cases it stalled in the state Senate, as it nearly did again this week. The bill passed late on Friday after legislators agreed on language allowing religious organizations to refuse to perform services or lend space for same-sex weddings.