Political newcomer Maura Healey, a former state prosecutor seeking to become the first openly gay attorney general in the nation, captured the Democratic nomination for attorney general on Tuesday following a primary race against a veteran state lawmaker.

The 43-year-old Charlestown resident defeated former state Sen. Warren Tolman of Watertown.

As assistant attorney general, Healey successfully argued the state’s case to overturn the federal Defense of Marriage Act, which critics said prevented legally married gay couples in Massachusetts from obtaining certain federal benefits.

She now faces Republican John Miller in the November election.

If elected, Healey would become the first openly gay female to hold a statewide office in Massachusetts. Current state Attorney General Martha Coakley is running for governor.

Tolman, who ran unsuccessfully for governor in 2002 and for lieutenant governor in 1998, pledged to support Healey in the campaign ahead.

Healey ran a spirited campaign against a better-financed opponent with strong ties to organized labor and Democratic state politics. Tolman raised $1.3 million to Healey’s $942,000.

He also enjoyed endorsements from Democratic party leaders, including Gov. Deval Patrick and Boston Mayor Martin Walsh. The Massachusetts AFL-CIO, which his brother, former state senator Steve Tolman, serves as president, was among the labor groups that endorsed him.

A basketball star at Harvard University who later played professionally in Austria, Healey campaigned, in large part, as the non-establishment candidate.

Healey, who holds a law degree from Northeastern University, called for repeal of the state’s casino gambling law, a position that put her at odds with Tolman and a number of other Democratic leaders.

She was endorsed by EMILY’s List, a political action committee that helps elect pro-choice Democratic female candidates, as well as the advocacy and political arm of the Planned Parenthood League of Massachusetts.

Join our Newsletter for the latest news right to your inbox