Thousands filled the Minnesota State Capitol as they waited for word that the Senate had passed the gay marriage bill Monday, May 13, 2013 in St. Paul, Minn. Photo: Jim Mone, AP Photo:

Thousands filled the Minnesota State Capitol as they waited for word that the Senate had passed the gay marriage bill Monday, May 13, 2013 in St. Paul, Minn. Photo: Jim Mone, AP Photo:

ST. PAUL, Minn. — The Minnesota Senate voted moments ago to legalize same-sex marriage, the last legislative step before Gov. Mark Dayton’s promised signature will make the state the 12th in the U.S. to do so.

The Senate vote of 37-30 came four days after the House passed the bill on a 75-59 vote. A cheer erupted in the chamber after the vote was announced, and spectators in a small gallery area stood and applauded.

Minnesota will become the first state in the Midwest to make gay marriage legal via a legislative vote. Iowa legalized same-sex marriage in 2009 through a court ruling.

Last week, Dayton, a Democrat, called the bill “one of those society-changing breakthrough moments.”

The governor’s staff announced his plans just moments after the state Senate passed the bill Monday. Dayton will sign the bill at 5 p.m. with legislators and supporters on hand in a ceremony Tuesday evening on the front steps of the Capitol in St. Paul.

Under the legislation, gay couples will be able to get married starting on Aug. 1.

It’s a rapid turnaround for gay marriage backers, who just six months ago had to organize a massive effort to defeat a constitutional amendment that would have banned gay marriage. The groups who defeated the amendment quickly turned their attention to legalizing gay marriage, and their efforts were aided by Democrats capturing full control of state government in November.

In the last week and a half, Rhode Island and Delaware became the 10th and 11th states to legalize gay marriage. In Illinois, a gay marriage bill has cleared the state Senate but awaits a House vote.

The House vote last Thursday drew more than a thousand demonstrators representing both sides of the issue. Supporters of gay marriage say they just want same-sex couples to have the same legal protections and societal validation that straight couples get with marriage.

Opponents say gay marriage undermines an important societal building block that benefits children, and also exposes people opposed on moral grounds to charges of bigotry.

Developing story, check back for updates.