LOS ANGELES (AP) — Retired Republican Judge Steven Bailey, once seen as a longshot in his attorney general campaign, will now face the incumbent in the November election after a solid second-place finish over a much better-funded and well-known Democrat and a Republican rival.

Bailey emerged from Tuesday's race with 25 percent of the vote — a long way behind Attorney General Xavier Becerra, a Democrat who led with 45 percent of votes — but enough to make the runoff. Insurance Commissioner Dave Jones, a Democrat twice elected to state office, and GOP attorney Eric Early each got less than 15 percent.

Bailey and his two other rivals hammered at Becerra's fixation on challenging President Donald Trump. Becerra, a longtime congressman appointed last year to fill the seat vacated when Kamala Harris was elected to the U.S. Senate, has filed dozens of lawsuits against the Trump administration.

Bailey said in a statement that he would lay out a vision challenging "the aggressively partisan posture of the current attorney general."

"I'm confident that Californians understand justice," Bailey said, "and will vote to elect a voice for crime victims, an advocate for our first responders, and the only candidate with a background and expertise in criminal law."

Bailey spent the smallest amount of the four candidates, with just over $235,000 and had less than $9,000 remaining in his account. Becerra spent $3 million and had $1.5 million remaining. Jones spent $2.4 million and had $2.3 million left in his account.

Bailey, 66, started his career as a legislative assistant and was later deputy legislative director for the state Department of Social Services. He has touted his criminal and administrative law experience during 19 years in private practice and more than eight years as El Dorado County Superior Court judge.

However, his time on the bench has landed him in ethical troubles with the state's judicial watchdog, including accusations of steering business to an electronic monitoring company where his son worked.

Bailey denied the allegations by the state Commission on Judicial Performance, which scheduled a September hearing to see if sanctions were warranted for improperly accepting gifts and using his office to advance his bid for attorney general.

Bailey said the case was politically motivated. Even though he's no longer a judge, he could be publicly admonished, but not disqualified from the attorney general's race.

Bailey has criticized Becerra for seeking to end the state's existing money bail system, which the AG said hits the poor harder.

Bailey opposed recent voter-approved initiatives that reduced criminal penalties and he supports the death penalty.

Despite his personal reservations, Becerra is taking steps to resume executions in California for the first time since 2006 after voters approved speeding up the death penalty in 2016.

Becerra, 60, the first Latino to hold the office, has filed more than 30 lawsuits against the administration, challenging policies on immigration, health care and the environment. He has defended that work and said he's also cracked down on gangs and charity fraud.

"As attorney general, I keep the experiences of hardworking families like the one I grew up in in mind," Becerra said in a statement Wednesday. "And it's my job to always fight to ensure that everyone who works hard deserves a chance to get ahead."

Becerra's Department of Justice was criticized last week by state auditors for not requiring local law enforcement agencies to do a better job reporting hate crimes to the FBI.

Becerra said in response that he had provided more guidance for local law enforcement and created a new hate crimes prevention webpage and brochure on identifying and reporting hate crimes.