Shortly before midnight Wednesday, Minneapolis Mayor R.T. Rybak stood before nearly 1,000 people at the foot of the white marble staircase inside City Hall. “It’s a tremendous honor to be able to do what we are about to do,” he said, before pausing. “We will talk about this for a couple more minutes.”

The audience snickered. It was only 11:57 — three minutes before Minnesota would join Rhode Island as the 12th and 13th states to legalize gay marriage. As the clock struck 12 a.m., the mayor continued: “By the power now finally vested in me, by the laws of the people of Minnesota, we hereby declare Margaret and Cathy legally married.” And with that, Margaret Miles and Cathy ten Broeke became one of the first same sex couples legally married in Minnesota, one of 66 such weddings (46 of them officiated by the mayor) performed at City Hall between midnight and 7 a.m. in a ceremonial blitz. For supporters, the night marked a historic victory years in the making. And it may never have happened were it not for the strong opposition of Minnesota Republicans.

Though they couldn’t have known it at the time, when state lawmakers passed a Republican-initiated ballot referendum for a constitutional amendment to ban same-sex marriage two years ago, they set off a series of events that led to this landmark day for gay rights.

“There is absolutely no doubt that without the amendment campaign, we wouldn’t be where we are today with marriage equality of the law in the state of Minnesota,” says Sen. Branden Peterson, a Republican who voted in favor of the putting the amendment on the ballot, and later flipped to co-author the same-sex marriage bill. “I say that with 100-percent confidence.”

Minnesota Republicans began trying to get a constitutional gay marriage ban in 2004. The efforts failed repeatedly until the party gained control of both houses of the legislature in 2010, buoyed by the Tea Party wave. In May 2011, with majorities in both chambers, the GOP passed the bill with enough signatures to bypass the signature of Democratic Governor Mark Dayton and sent the question to the voters.

The amendment seemed likely to succeed. 30 other states had passed similar measures and early polling on Minnesota’s ban indicated it would be approved with a more than 10 percent margin of voter support.

But the bill’s proponents were unprepared for the organized effort of the backlash. Rather than turn the fight into a civil rights battle, a strategy that had failed in other states, opponents framed the amendment as an unprovoked attack on families of all types. Under the umbrella of the political committee Minnesotans United for All Families, same-sex marriage defenders recruited 50,000 volunteers and raised $11 million – double the amount taken in by the opposition group Minnesotans for Marriage, according to campaign finance reports. In just the week before the election, the group made almost 500,000 phone calls and knocked on nearly million doors.

“It just caught fire,” says Sen. Scott Dibble, a Minneapolis Democrat who helped lead the legislative opposition. “We just knew we could win, and the only way we could do it was raise a bunch of money and throw our bodies into it.”

The gay marriage ban was narrowly defeated and the vote proved devastating for Republicans. Mobilized by their opposition to the gay marriage ban and a presidential election, Democratic voters turned out in droves, particularly in crucial suburban districts. They voted not only against the bill, but threw out many Republicans, too, costing the party their majorities in both the state House and state Senate. An amendment born of the party’s control of government led directly to its loss of it.

“They misinterpreted, I think, how this issue would energize young people and liberals more so than it would mobilize the conservatives,” says David Schultz, a professor of law and government at Hamline University. “It turned out to be a counter mobilization.”

After the election, Minnesota Democrats found themselves in an unexpected position of opportunity. For the first time in more than 20 years, they controlled the House, Senate and governor’s office. After some inner-party debate on how to move forward, legislators introduced bills to legalize gay marriage. With significant support from Minnesotans United, which restructured as a lobbyist group in late 2012 to push for gay marriage, the measures passed and were signed into law on May 14th.

“It’s one of the great ironies, I think, of the whole legalization of gay marriage,” says Larry Jacobs, a political science professor and elections expert at the University of Minnesota, “because it probably would never have happened if it wasn’t for Republicans.”