A Republican lawmaker and a Democrat who strongly supports same-sex marriage were locked in a tight battle Tuesday in a special election for the state Senate that was seen as a key test of gay marriage as a campaign issue.

The election was held to replace former Democratic state Sen. Cheryl Jacques (search), a proponent of same-sex weddings who resigned to head the Human Rights Campaign (search), a national gay-rights organization.

The Republican candidate, state Rep. Scott Brown (search), opposes gay marriage but says he would support same-sex civil unions. The Democrat, Angus McQuilken (search), is a strong supporter of marriage rights for gay couples and served as Jacques' chief of staff for 10 years.

With all precincts reporting, Brown led McQuilken by only about 330 votes. Brown declared victory, but McQuilken said he was considering a recount.

The special election in the district south of Boston also was seen as a bellwether of Republican hopes to capture more seats in the heavily Democratic Legislature come November.

The election comes a week before Massachusetts lawmakers reconvene a joint session of the House and Senate to consider a ban on gay marriage.