With Gov. Martin O’Malley’s signature Thursday, Maryland joined seven other states that, along with the District, have legalized gay marriage.

A crowd of supporters descended on Annapolis for a scheduled 5 p.m. ceremony at the State House and erupted into sustained applause after O’Malley signed the bill.

Sen. Richard Madaleno (D-Montgomery) celebrates with Rep. Maggie McIntosh (D-Baltimore City), left, and Rep. Heather Mizeur (D-Montgomery), all three of whom are openly gay, after the Senate approved a gay marriage bill. (Patrick Semansky/AP)

Thursday’s signing gave O’Malley (D) a chance to bask in a landmark legislative success that was not at all certain when he took on the issue as his own last year. O’Malley, who is Catholic, had long said he preferred civil unions to gay marriage.

Since the measure’s passage, O’Malley has publicly explained his changed position in greater detail, saying he “misjudged” how quickly the public’s views of gay marriage had evolved. Detractors have said O’Malley’s opinions only seemed to change last year when another potential candidate for his party’s 2016 presidential nomination, New York Gov. Andrew Cuomo (D), was able to secure passage of gay marriage through a divided state legislature.

Regardless, celebration ensued Thursday. With dozens of advocates lined up behind him and with hundreds of onlookers cheering, O’Malley signed the bill in the marble-lined main hall of the State House in Annapolis.

In one of the grandest stagings for any bill signing in recent memory, O’Malley, Senate President Thomas V. Mike Miller Jr. (D- Calvert) and House Speaker Michael E. Busch (D-Anne Arundel) sat at a table erected at the bottom of a marble staircase leading to the second floor of the State House and O’Malley’s office.

Behind O’Malley was Lt. Gov. Anthony G. Brown (D) and First Lady Katie O’Malley who had also advocated forcefully for the bill.

More than 50 gay rights leaders and clergy members lined the ascending staircase. Hundreds of onlookers, lawmakers and 15 television cameras crowded in the hallway.

“For a free and diverse people, for a people of many faiths, for a people committed to the principle of religious freedom, the way forward is always found through greater respect for the equal rights of all, for the human dignity of all,” O’Malley said.

“Religious freedom was the very reason for our state’s founding, and at the heart of religious freedom is the freedom of individual conscience.

“If there is a thread that unites all of our work here together, it is the thread of human dignity, the dignity of work, the dignity of a job, the dignity of every child’s home, the dignity of every individual.”

The ceremony was over in less than five minutes. O’Malley then lingered and posed for pictures with anyone who wished.

But as the crowd was filing out, there was also no question among advocates that work remains.

Opponents of gay marriage are widely expected to meet Maryland’s relatively low threshold for signature-gathering to petition the measure to the November ballot.

On Wednesday, a group of Maryland Republicans who set up an online tool to gather signatures was joined by a handful of black Democrats from Baltimore and the Maryland Marriage Alliance, a religious group affiliated with some of the state’s black churches, to launch a petition drive.

Whether or not the measure appears on the ballot, no gay nuptials can begin under the law until Jan. 1, 2013.

With a final battle over gay marriage in the state likely to come down to the ballot, proponents say they are hopeful that Maryland may mark a turning point nationally for gay rights.

A recent Washington Post poll showed the state’s electorate nearly equally divided over the issue. Gay marriage has never passed by a popular vote.

Marylanders for Marriage Equality has said it hopes to win the battle by grass-roots campaigning and personally connecting with voters.