SAN JOSE, Calif. (AP) - In the race for California governor, two Republicans have shunned the center and are running to the right in a bloody fight for a segment of the electorate that loves President Donald Trump and loathes Democrats who have proudly committed to being his foil.

Democrats dominate California’s government and far outnumber Republicans in the state. But Assemblyman Travis Allen and businessman John Cox haven’t altered their messages to try to appeal to them in a June 5 primary where every registered voter can cast a ballot for any candidate.

Eight years ago California voters rewrote the state’s election laws so that the top two finishers in the primary, regardless of party, advance to the general election in November. It was pitched as a way to give moderates a path to victory, but in this race the Democrats are running to the left and the Republicans to the right.

Cox and Allen went at each other repeatedly in Tuesday night’s debate in San Jose that also included the four leading Democratic candidates. The conflict between the Republicans became heated enough that moderator Chuck Todd of NBC News quipped that they should take their battle outside.

Allen called Cox “my angry opponent from Chicago,” a reference to his native city that many Republicans identify with crime and Democratic corruption. Cox called Allen “my young immature opponent.” They talked over each other and Allen accused Cox of lying in a dispute about how Allen voted on a 2013 bill that granted driver’s licenses to people living in the country illegally.

Allen and Cox fought over who has pushed harder to repeal a recent increase in gas taxes and vehicle registration fees. Both backed competing initiatives, though only Cox’s turned in a substantial number of signatures, which are being verified. Both committed to fighting California’s new “sanctuary state” law that restricts cooperation between law enforcement and federal immigration authorities.

And they argued about their support for Trump.

“I’m the only person on this stage that voted for, supported, even wrote op-eds in favor of the Republican nominee, Donald J. Trump,” Allen said.

Cox voted for Libertarian Gary Johnson, but said he regrets it. He doubted whether Trump was truly conservative, he said, but has been satisfied.

“I think this whole fight between California and the Trump administration is not productive,” Cox said.

Larry Gerston, a professor emeritus of political science at San Jose State University, noted California’s two most recent GOP standard-bearers for governor - Meg Whitman in 2010 and Neel Kashkari in 2014 - took more moderate positions and still lost to Democrat Jerry Brown. The Republican Party’s base has moved to the right, and the GOP candidates were clearly speaking to them at the debate, he said.

Allen and Cox “realize they don’t have much to lose, so they’re going to go out with guns blazing,” Gerston said.

Lt. Gov. Gavin Newsom, a Democrat, is the odds-on favorite to win on June 5. Republicans hope Newsom and the other three major Democrats - former Los Angeles Mayor Antonio Villaraigosa, state Treasurer John Chiang and former state education Superintendent Delaine Eastin - drain away enough votes from each other that Allen or Cox can make it to November.

Allen is a three-term state assemblyman from Huntington Beach and was previously a financial adviser. He’s struggled to raise money - he reported just $150,000 in the bank last month, a pittance in sprawling California. But he’s fired up many grassroots activists and cultivated relationships in local GOP committees and conservative groups.

He speaks their language, decrying what he calls “leftist propaganda” in public education and the “Bay Area liberal elites” he says run California. He paints a bleak picture of cities run by Democrats with dense urban living and decay caused by rising homelessness.

Cox is an accountant, former attorney and investor who owns apartment complexes. He ran unsuccessfully for U.S. House and Senate and county recorder in his native Chicago, and even for president. Cox bought his house in California in 2007 and moved here full time in 2011, spokesman Matt Shupe said.

He’s highlighted his business experience and touted his plan to create thousands of neighborhood-level districts with elected representatives who would choose the members of the state Legislature. Despite his prior attempts at public office, he calls himself a political outsider and blames elected officials from both parties for making California an expensive place to live.

“I’m sick and tired of what the politicians have done to this state,” Cox said. “They’ve mismanaged just about every aspect of life here. They’ve made it unaffordable.”

Cox has poured $4 million of his own money into his race and has lined up support from much of the GOP establishment, including Newt Gingrich and the state’s most powerful Republican, U.S. House Majority Leader Kevin McCarthy of Bakersfield, who hopes to be the next House speaker.

Neither Cox nor Allen obtained the state GOP endorsement at the party’s convention last week in San Diego, though Cox came close.