Marylandd Gov. Martin O'Malley (D) on October 3, 2012. (Aaron C. Davis/THE WASHINGTON POST)

After mingling for about 20 minutes at the bar, Maryland Gov. Martin O’Malley made his way to a table near the back of the dining room at Casa Lever, a trendy Italian restaurant on Manhattan’s Park Avenue adorned by Andy Warhol prints.

Over ravioli and red wine, O’Malley (D) made his pitch for help to actor Josh Charles, a Baltimore native, and Charles’s friend Brian Ellner, who had run a costly campaign to build public support for same-sex marriage legislation in New York last year.

We can win this thing in Maryland — we have the right message, O’Malley told them during a wide-ranging conversation that also veered into national politics and the health of the Chesapeake Bay, according to an aide at the table.

Commitments made at the June dinner led to a star-studded fundraiser in September in New York to benefit Maryland’s same-sex marriage campaign. It raised more than $100,000, raised the profile of the race, and was emblematic of the kind of effort that O’Malley put into an election that could hardly have turned out better for him.

Besides the victory on gay marriage, O’Malley also prevailed — through a combination of pluck and good luck — on ballot measures he pushed to extend in-state college tuition rates to undocumented immigrants and to expand the state’s gambling program.

He also claimed victory when voters overwhelmingly approved the newly redrawn congressional map, which even a fellow Democrat had called an “egregious gerrymander” that resembled “blood splatter from a crime scene.

Some issues O’Malley clearly cared about more than others, but all had become closely identified with him and carried political consequences win or lose.

“It was almost as though he was standing for a second reelection,” said Thomas F. Schaller, a professor of political science at the University of Maryland Baltimore County. “To a certain degree, his administration was on the ballot.”

O’Malley acknowledged that he had never had to “multi-task” as much during an election season, and he faced some grumbling from activists who felt he wasn’t focused enough on their issue. But he seemed to surface at key moments.

When, for example, opponents of the expanded-gambling measure were flooding the airwaves with ads questioning whether money would go to schools, as promised, O’Malley appeared in an ad himself and confronted head-on the claim that you can’t trust politicians.

“I felt it wasn’t right to let them get away with this,” he said in an interview. “It became kind of obvious to me that not to speak up would be irresponsible.”

Although he was outspoken in his support of each of the measures on the ballot Tuesday, much of the work O’Malley did to bolster their chances took place behind the scenes.

Key players from his political organization — polling, fundraising and media consultants, as well as his 2010 campaign manager — were dispatched to work on the key ballot measure campaigns.

During the same June trip to New York, O’Malley also solicited donors to help the campaign for Maryland’s version of the Dream Act.

O’Malley, who heads the Democratic Governors Association, escaped the kind of collateral damage from that position that had seemed likely just a few weeks ago. His party lost one governorship but fared far better than expected Tuesday in what had been shaping up as big year for Republicans at the statehouse level.

“I’m not sure I’ve ever been so relieved at the end of an election where I wasn’t on the ballot,” O’Malley said, referring to the DGA results, the ballot measures and the victory of President Obama, for whom O’Malley raised money and appeared as a surrogate on the Sunday talk shows.

O’Malley aides said that at several points during political travels for the DGA, O’Malley appeared at fundraisers to benefit Maryland’s same-sex marriage and Dream Act campaigns, tapping the national interest in the issues.

The money appeared key in the same-sex marriage campaign in particular. Two weeks before the election, Marylanders for Marriage Equality had raised $4.5 million for its efforts, more than 21 / 2 times as much as the leading opposition group. That led to a more robust television ad campaign in the closing weeks of the election.

The victories on the four ballot measures should help secure some key parts of O’Malley’s legacy in Maryland and strengthen his pitch to Democratic activists if he chooses to move forward with a 2016 presidential bid, as many suspect he will.

The gay community has emerged as a key fundraising source for national Democrats. And Tuesday’s presidential election proved that Latinos, who championed the Dream Act, are becoming a stronger, more organized force in politics every year.

Despite the obvious political upside of Tuesday’s wins, O’Malley has told reporters that one of the lessons was that it’s “a little too easy” for opponents to petition laws to Maryland’s ballot. Three of the measures — same-sex marriage, the Dream Act and the congressional map — were put to a public vote because of successful petition drives.

Tuesday’s votes also tied O’Malley more closely to issues popular with Democratic activists that he was not among the first to embrace.

For much of his political career, O’Malley was a supporter of civil unions as an alternative to same-sex marriage. It was only after a marriage bill narrowly failed in the 2011 legislative session that he agreed to sponsor the legislation going forward.

By that time, similar legislation had passed in New York, championed by Gov. Andrew M. Cuomo, a potential rival for the Democratic nomination for president in 2016.

Asked about his decision, O’Malley said: “The biggest single influence was a sense that the time was ripe and people were ready to do this with some leadership.”

While O’Malley helped raise money for the cause, the most visible spokesmen during the television campaign were a pair of African American ministers who argued that same-sex marriage would not infringe upon the religious practices of those opposed to it.

Their message was tacit acknowledgment of the importance of the African American vote in a state where black voters make up a greater share of the electorate — 28 percent, according to Tuesday’s exit polls — than anywhere outside the Deep South.

While O’Malley signed the Dream Act legislation in 2011, it was not a bill his administration sponsored that year. Thirteen other states, including Texas, have passed similar measures. But with its passage Tuesday, Maryland became the first state to adopt a version of the Dream Act by popular vote.

O’Malley has never been a big proponent of gambling, but he embraced a bill this summer, saying it was a way to put the divisive and heavily lobbied issue behind him in Annapolis. Tuesday’s vote may have accomplished that, for the most part.

Although the decision by voters to uphold the congressional map did not get much attention, or draw very organized opposition, the result will no doubt be welcomed by national Democratic leaders.

On Tuesday, it helped the party pick up another seat in Congress.