Gay marriage is all but legalized in Maryland after the legislature gave its final OK Thursday to the law that's being sent to Gov. Martin O'Malley, who said he expects to sign it sometime this week.

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 O'Malley — who sponsored the bill — signs the legislation. The Democrat made the measure a priority this session after it stalled last year.

"This issue has taken a lot of energy, as well it should, and I'm very proud of the House of Delegates and also the Senate for resolving this issue on the side of human dignity, and I look forward to signing the bill," O'Malley said in a brief interview after the Senate vote.

Opponents, though, 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.