The state senate voted 25-22 for the law. The vote comes less than a week after the House of Delegates barely passed the measure.
Maryland will become the eighth state to allow gay marriage when Governor Martin O'Malley who sponsored the bill signs the legislation. The Democrat made the measure a priority this session after it stalled last year.
Six states allow gay couples to wed Connecticut, New Hampshire, Iowa, Massachusetts, New York and Vermont as well as the Washington capital district. The governor of Washington signed a bill this month that would make that state the seventh.
Opponents in Maryland have vowed to bring the measure to referendum in November. They will need to gather at least 55,726 valid signatures of Maryland voters to put it on the ballot and can begin collecting names now that the bill has passed both chambers.
Some churches and clergy members have spoken out against the bill, saying it threatens religious freedoms and violates their tradition of defining marriage as between a man and a woman.
"The enormous public outcry that this legislation has generated voiced by Marylanders that span political, racial, social and religious backgrounds demonstrates a clear need to take this issue to a vote of the people," Maryland Catholic Conference spokeswoman Kathy Dempsey said in a statement. "Every time this issue has been brought to a statewide vote, the people have upheld traditional marriage."
Leaders at the Human Rights Campaign, a group that joined a coalition of organisations to advocate for the bill, said they expect opponents will gather the required number of signatures.
Senator Allan Kittleman, the only senate Republican to vote in favuor of the legislation, said he is proud of his decision and not concerned about political consequences down the road.
"You don't worry about politics when you're dealing with the civil rights issue of your generation," said Kittleman, R-Howard, the son of the late Senator Robert Kittleman, who was known for civil rights advocacy.
Gay marriage remains on hold in California after opponents petitioned a federal appeals court on Tuesday to review a split decision by three of its judges that struck down a voter-approved measure that limited marriage to a man and woman.