ALBANY – Letitia James, the New York City public advocate, won the four-candidate race for the Democratic nomination for attorney general.

James led with 42 percent of the vote with 70 percent of precincts reporting, according to the Associated Press, which called the race for her at 10:30 p.m.

That compared to 31 percent for Zephyr Teachout; 24 percent for Rep. Sean Patrick Maloney, D-Cold Spring, Putnam County; and 3 percent for Leecia Eve.

The resignation of Attorney General Eric Schneiderman earlier this year set off a free-for-all to replace him, with four viable candidates squaring off in the primary.

James went into the race as the perceived favorite after she easily secured the state Democratic Committee's endorsement at its convention in May.

She has drawn the support of Gov. Andrew Cuomo, and she has vowed to be independent of the Democratic governor if she's elected.

If she wins in November, James would be the first African-American woman elected to statewide office in New York.

"As attorney general, I will never hesitate to stand up to the forces in New York or Washington who try to move us backwards and deny our most basic rights," 59, of Brooklyn, said in a recent statement.

James will face Republican Keith Wofford, a Manhattan attorney, in the general election, Nov. 6. The post is a four-year term.

Her opponents, however, knocked her closeness with Cuomo, saying the state's top attorney needs to keep the executive branch at arm's length.

"This notion that the attorney general should be some running mate or little buddy to the governor is outrageous," Maloney told the USA Today Network's Albany Bureau last month.

Maloney, 52, pumped more than $1.4 million from his congressional campaign into his run for attorney general, blitzing the state with ads in advance of the primary.

He is now expected to run for re-election in November to his House seat.

In a Siena poll Monday, Maloney and James were running neck and neck, while Teachout, a Fordham Law professor, close behind.

The race has been largely focused on the candidates vowing to fight the policies of the Trump administration.

They each pledged to sue and battle White House initiatives that could hurt New Yorkers, such as those dealing with immigration and the environment.

Having a competitive primary for attorney general in New York was not expected.

Schneiderman planned to seek a third term, but resigned in disgrace in May after women accused him of abuse.

Barbara Underwood was appointed attorney general after Schneiderman resigned, and she will hold the position until Jan. 1 when the elected candidate takes office.

Teachout, 46, ran for governor in a Democratic primary against Cuomo in 2014 and lost, but did better than expected. Then she lost in 2016 in a congressional bid against Rep. John Faso, R-Kinderhook, Columbia County.

For Eve, 53, a Buffalo native and now a New York City attorney, she has sought to promote her experience in government and in private practice, offering an alternative to the three leading candidates.