Letitia James was overwhelmingly elected as the attorney general of New York on Tuesday, shattering a trio of racial and gender barriers and placing herself in position to be at the forefront of the country’s legal bulwark against the policies of President Trump.

[New York Attorney General Letitia James sues the NRA.]

With her victory over Republican nominee Keith H. Wofford, Ms. James, 60, the public advocate for New York City, becomes the first woman in New York to be elected as attorney general, the first African-American woman to be elected to statewide office and the first black person to serve as attorney general.

The victory follows a rugged political season that arose after the surprise resignation of former attorney general Eric T. Schneiderman, following charges that he physically abused multiple women. Ms. James will succeed Barbara D. Underwood, who was appointed by the State Legislature in May to complete Mr. Schneiderman’s term.

Ms. Underwood already has dozens of cases pending against Mr. Trump, including an investigation into his charity and lawsuits to stop immigrant families from being separated at the border and to block the rollback of net neutrality and environmental regulations.