"This campaign was really never about me, or any of the candidates who ran," James told supporters at her victory party in Brooklyn. "It was about the people, but most importantly it was about that man in the White House who can't go a day without threatening our fundamental rights, can't go a day without threatening the rights of immigrants, can't go a day without dividing us."
For the 59-year-old former public defender, history is at stake, too. She would become the first black woman to hold a statewide elected office in New York if she prevails in the general election, where she will be heavily favored.
She would also become the first woman elected attorney general, though not the first to hold the job. The current attorney general, Democrat Barbara Underwood, was appointed after Trump nemesis Eric Schneiderman, a Democrat, abruptly resigned in May amid allegations he physically abused women he dated. Underwood declined to run for election.
"This is a historic moment, it shows that there's room for all of us at the table," James supporter Michelle Gilliam said. "As a black woman, Tish elevates and inspires black women everywhere. I've been following her career since the beginning and watching her progress has been a beacon of hope for me and all women of this community."
James defeated a deep field of fellow Democrats: U.S. Rep. Sean Patrick Maloney, Fordham law professor Zephyr Teachout and former Hillary Clinton adviser Leecia Eve. She said she wouldn't let campaign rivalries get in the way of their friendships or impede their ability to work together to keep Trump in check.
New York's attorney general has long had an unusual role as a regulator of Wall Street and an occasional prosecutor of the rich and powerful. The office also recently opened an investigation of sexual abuse within the Roman Catholic Church. But in this contest, Trump emerged as the common foe among all the candidates.
"We are in the middle of a fight to save our democracy," she said. "Let's party tonight and then we've got some work to do tomorrow."
The winner in November will inherit several pending lawsuits filed by the state that challenge Trump's policies and accuse his charitable foundation of breaking the law.
James faces little-known New York City lawyer Keith Wofford, who ran unopposed in the Republican primary, in the general election in November.
Wofford, in a statement, criticized James as a "career politician" who will "uphold the corrupt status-quo." He pitched himself as an "independent outsider" and said he'd do what's in the state's best interests.
James served as New York City's elected public advocate after a decade on the City Council and stints as a public defender and assistant attorney general. She was an early favorite in a race that tightened over the summer, picking up endorsements from Democratic Gov. Andrew Cuomo and several powerful unions. Rapper Nicki Minaj plugged her on Twitter the night before the election.
As public advocate, James said she transformed the office from its traditional role as an ombudsman on issues of public concern to a "mini-legal services slash attorney general's office."
She lobbied for police officers to wear body cameras and for special prosecutors to be appointed in police misconduct cases. Her office maintains a list of the "worst landlords" in the city and has pushed to expand tenant protections.
James entered her victory party to the sounds of a DJ playing "All the Way Up" by Fat Joe and Remy Ma. She dedicated her victory to "every little girl who has been told she cannot change the world" and singled out an 87-year-old supporter who cast her first vote decades ago in the Jim Crow south.
Underwood congratulated the candidates in a tweet before the polls closed for showing they "believe in the power of this office" and for giving voters "a choice for the future."
"After the events of this year, I hope it is clear to everyone that this office is the sum of all its staff," Underwood tweeted. "I am so proud to be your AG."
Trump's lawyers have argued that the attorney general's office was unfairly politicized under Underwood and Schneiderman.
The adversarial relationship dates back to 2012, when Schneiderman sued Trump University, claiming the school defrauded students. Trump settled litigation related to the school for $25 million, saying he was doing so only so he could keep his attention focused on national issues.
In defending the state's lawsuit against the Trump Foundation, Trump's lawyers said New York built its case on minor, unintentional bookkeeping violations and unnecessarily blocked the charity from shutting down simply so it could continue to assail it in court.
The legal sparring is likely to continue. The attorney general's office has lawsuits pending against Trump administration policies on health care, guns, immigration and the environment.
Associated Press writer Sabrina Caserta contributed to this report.
Follow Sisak at twitter.com/mikesisak
Copyright 2019 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.