Twitter.com @GovMarkDayton posted this photo on Twitter.com, with the caption "It's history"

As thousands cheered outside the state Capitol with rainbow and American flags, Governor Mark Dayton signed a bill on Tuesday that makes it possible for same-sex couples to get married.

Minnesota is the 12th state to pass a gay marriage bill and the first Midwestern state to do so through a legislative vote.

"What a day for Minnesota!" Dayton, a Democrat, declared moments before putting his signature on a bill. "And what a difference a year and an election can make in our state."

The bill was signed a day after it was approved by the Senate in a 37-30 vote.

"It is an overwhelming joyful day, the culmination of years of work. Two years ago it would have been unimaginable to be here," said Jake Loesch, communications director with Minnesotans United, a LGBT group. "It was incredible, we had 7,000 people cheering as the bill as signed, it was probably the biggest crowd the Capitol has ever seen,"

Gay activists from all over the country cheered this decision.

"The transformative nature of people talking about their love and their lives is clear, as we see in reaching this milestone in Minnesota, and in the fact that a clear and growing majority of Americans supports the freedom to marry," said Rea Carey, executive director of National Gay and Lesbian Task Force.

“The many years of door-knocking, phone calls and poignant conversations about why marriage matters have made a difference.”

And Minnesotans United tweeted: “Freedom prevails. Thank you, Minnesota!”

The push for gay marriage was a quick change from just six months ago, when LGBT supporters had to mobilize to turn back a proposed constitutional amendment that would have banned same-sex unions. Minnesota already had such a law, but an amendment would have been more difficult to ever undo.

But voters rejected the amendment, and the forces that organized to defeat it soon turned their attention to legalizing gay marriage. Democrats' takeover of the Legislature in the November election aided their cause.

"There is still a lot of work to be done. Now we have to make sure that all the legislators that made this day possible will be reelected," said Loesch.

Tonight, the city of Saint Paul is hosting a party to celebrate this historical moment. The law will go into effect on August 1.

The Associated Press contributed to this report