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

James had 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. EDT.

That compared with 31 percent for Zephyr Teachout; 24 percent for Rep. Sean Patrick Maloney; and 3 percent for attorney Leecia Eve.

The resignation of state 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.

More:Andrew Cuomo cruises to easy win over Cynthia Nixon in New York gubernatorial primary

She has drawn the support of Gov. Andrew Cuomo, and she has vowed to be independent of the Democratic governor if 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," James, 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.

But in her acceptance speech, James said that will not be the case.

"I will be that independent individual I have been for the last 20 years,” she said.

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 resume running 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, was close behind.

James won overwhelmingly in New York City, leading her to victory, the results showed.

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 multiple 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 Republican Rep. John Faso.

Eve, 53, a Buffalo native who is now a New York City attorney for Verizon, had sought to promote her experience in government and in private practice, offering an alternative to the three leading candidates.