Voters also passed a state version of the Dream Act, allowing some illegal immigrants to pay in-state tuition rates at state colleges and universities.
Obama carried the state with just over 60 percent of the vote, The Washington Post reported. His Republican challenger, Mitt Romney, had 37.9 percent of the vote.
The Board of Elections reported Question 6, which would legalize civil marriage for same-sex couples in Maryland, had 51.9 percent of the vote, to 48.1 percent against. Similar measures were on the ballot in three other states, and the one in Maine was approved.
The question got a boost when Obama came out in support of gay marriage. In Montgomery County, in the Washington suburbs, it passed 2-1, the Post said.
Same-sex couples can apply for marriage licenses starting Jan. 1, The Baltimore Sun reported.
"To Maryland's children -- please know that you and your families matter to the people of our state," Gov. Martin O'Malley said early Wednesday in a statement. "Whether your parents happen to be gay or straight, Democratic, Republican or Independent, your families are equal before the eyes of the law."
The Rev. Derek McCoy, executive director of the Maryland Marriage Alliance, said his group and other opponents of the law were "well outspent." O'Malley, who signed a law legalizing same-sex marriage only to have the issue thrown to the voters, raised money outside Maryland to win support.
Maryland became the first state to adopt by popular vote a measure allowing some illegal immigrants to pay in-state tuition at state colleges and universities. Thirteen states have laws on the books adopted by legislatures.
A controversial referendum on expanding casino gambling was also leading by a slim margin. The question would allow table games as well as slot machines in the country and would add a sixth casino in Prince George's County near Washington.
Notable deaths of 2014 [PHOTOS]