Once again, Martin O’Malley has shown why he’s one of the very best at running and winning an election campaign. He did it again this week by pulling off a difficult grand slam — securing a second term for Barack Obama and mounting a successful defense of bills permitting gay marriage, a casino in Prince George’s County and in-state tuition for kids of illegal immigrants.

O’Malley’s first objective took him all over the country, with lots and lots of face time on network news shows. He proved a highly attractive, aggressive and quotable pitchman for Obama. It earned lots of bonus points with the president and could lead to a key Cabinet appointment between now and the end of O’Malley’s term in 2014.

The other objectives required sophisticated organizing and advertising campaigns. Each referendum question could have gone down to defeat. Two were close because of strong, well-financed opposition.

The “Dream Act” in-state tuition question won in a walk, in part because the opposition was hapless and disorganized. O’Malley played a central role in lining up voter backing for Question 4.

O’Malley helped give the gay-marriage coalition a critical push in the final weeks. The group hammered home the message that this is not a threat to society but a matter of giving everyone equal rights.

County-by-county results were almost break-even — yes in conservative Anne Arundel by 10,000 votes, yes in conservative Frederick by 1,500, no in Prince George’s by 4,000 and yes in Baltimore County by 11,000.

The coalition won by building a 30,000-vote margin in Baltimore city (surprisingly low) and a whopping 120,000 vote margin in Montgomery County. That was enough to ensure victory.

Even more difficult for O’Malley was voter approval of expanded casino gambling. It looked like opponents, led by Penn National Gaming, would defeat the bill thanks to incessant but effective negative advertising.

Then the governor put together a strong counter-advertising blitz featuring Democratic mayors and county executives and former county executives (Jim Smith from Baltimore County and Wayne Curry from Prince George’s) arguing that the new law would mean more jobs, more money directed toward education and a boost for economic development.

O’Malley’s operatives localized what had been an off-target campaign run by out-of-state professionals. Voters ended up believing their leaders rather than a West Virginia casino.

Question 7 was won in Prince George’s and Montgomery counties, which combined to give expanded gambling a 105,000-vote margin. It won by roughly 96,000 statewide.

In other counties, the margins were thin in either direction and canceled each other out — yes in Baltimore city by 8,000, no in Baltimore County by 10,000, yes in Frederick by 4,500, no in Anne Arundel by 20,000.

Still, we haven’t heard the end of this costly ($90 million) casino fight. Even before results were final, Penn National’s mouthpiece group announced it was pursuing litigation to annul approval of a Prince George’s casino. “[W]e intend to explore all of our legal avenues,” the Penn National group said.

Given the legal roadblocks thrown up to delay construction of a slots facility in Baltimore city, it’s safe to predict a Prince George’s casino, with slots and table games, could be many years away. That’s too bad for Maryland’s treasury, which stands to gain hundreds of millions of tax dollars each year.

But it is great news for Penn National’s Charles Town, W.Va., full-service casino-hotel. The longer Penn National (and Maryland Live! in Anne Arundel County) can prevent construction of a Washington-area casino, the fatter their bottom lines.

O’Malley clearly was a big winner on Election Day, even though his name wasn’t on the ballot this time. The biggest loser might have been Comptroller Peter Franchot, who linked arms with Penn National in ads to kill expanded gambling. One senator dubbed Franchot “the comptroller from West Virginia.”

Aligning with an out-of-state gambling company to deny economic development (and tax revenue) to Maryland will be used as ammunition by Franchot’s political foes in the next gubernatorial campaign.

— Baltimore County Executive Kevin Kamenetz, who was the missing Democratic county executive in ads supporting the referendum questions;

— Del. Pat McDonough of Baltimore County, who was unable to win even his own county for his pet project — defeat of the in-state tuition question.

— Rob Sobhani, whose pie-in-the-sky promises and $6 million personal spending spree netted him just 409,000 votes and a third-place finish for U.S. Senate.

— U.S. Sen. Ben Cardin, who coasted to victory despite producing the worst commercials of the campaign — pointless footage of Cardin hauling airline baggage, dredging oysters and playing cards at a senior community. Is that what a senator does to earn his pay?

Barry Rascovar is a political columnist and a communications consultant. He can be reached at brascovar@hotmail.com.