LOS ANGELES — After greeting the election of Donald J. Trump with a defiant stream of attacks, California Democrats are now divided over how best to deal with an administration whose policies on immigration, health care and the environment loom as a threat to years of established law here.

Many Democrats say they want to go to the barricades, arguing that this unconventional president will respond only to forceful opposition. But others are urging a more measured diplomacy, warning that confrontation alone could further isolate a state already viewed by the White House as the center of resistance to Mr. Trump.

This debate, which reflects a similar one going on among Democrats in Washington, has begun to shape next year’s contest for governor. Candidates seeking to succeed Gov. Jerry Brown see a political benefit in tough talk as they campaign for support from an overwhelmingly Democratic electorate.

“We’ve got to be bold in the face of this threat — and we have got to push,” said Gavin Newsom, the lieutenant governor, a Democratic candidate for governor. “We need to demonstrate that we have people’s backs. This is crunch time for political leadership and courage. If you don’t have it, I think you should step aside.”

As evidence of that, Democrats in Sacramento are pushing legislation that would require the state’s huge pension systems to divest from companies that take contracts to work on the wall Mr. Trump wants to build along the Mexican border.

And the Senate voted Monday on legislation pushed by Kevin de Leon, the Democratic leader of the Senate, to make California a so-called sanctuary state, restricting police and other authorities from enforcing immigration laws. The vote came despite a threat by Jeff Sessions, the attorney general, to cut off funding to communities that resist federal immigration crackdowns.

By contrast, a more pragmatic dynamic is emerging for Democrats who are more settled in office and who need the cooperation, or at least not the opposition, of the administration as they advocate for high-profile projects or against massive cuts in federal aid.

“It may feel good to take certain actions, but that could result in real hurt on the ground,” said Eric M. Garcetti, the mayor of Los Angeles. “My responsibility is to make sure that I bring resources back to my city that come from tax dollars we send to Washington. To shut off communication would hand a double victory to the people who want to take our money and tell us we have to share their values.”

”The civil right movement was not won by calling Bull Connor a racist,” he said. “He was a racist. But it was won by saying we should be at that lunch counter.”

Mr. Garcetti said that during a visit to Washington, Los Angeles officials met with Gary Cohn, the president’s top economic adviser, about getting a share of the public works investment program Mr. Trump has pledged to propose. Mr. Brown, in a recent Washington visit, met with Elaine Chao, the secretary of transportation, to lobby for support for a high-speed rail project.

“I know some people feel very strongly, so I don’t want to minimize their ardor,” Mr. Brown said while in Washington. “At the same time, we want to work with Mr. Trump. If it isn’t a trillion dollars, it’s tens of billions that California can get.”

Democrats are trying to balance the powerful anti-Trump sentiment among Democratic voters with the awareness of the threats California now faces with the Trump Administration, captured most recently by the failed health care bill, which would cost the state close to $20 billion in aid. At the same time, they are trying to figure out the extent to which Mr. Trump responds to the traditional tools of a political negotiation: Compromise, cajoling and threat.

Rob Stutzman, a longtime California Republican strategist who led an anti-Trump movement last year, said Democrats were at risk of provoking a backlash that could hurt the state.

“The Democrats have to be careful of overreach,” he said. “A statewide sanctuary law, that’s an overreach. That’s exposing a lot of their members to a bad vote.”

A poll of California residents last month by the Institute of Governmental Studies at the University of California at Berkeley found that 53 percent opposed state and local governments being permitted to ignore requests from federal authorities to detain illegal immigrants. But even though Mr. Trump is extraordinarily unpopular in this state, Californians, by a margin of 53 to 37 percent, said state leaders should work with him when they disagree with him, rather than risk consequences of pure defiance.

Mr. Brown, who at 78 is now in his fourth term as this state’s chief executive, walked that line in Washington as he met with Trump administration officials, but also offered a fiery speech at a rally of Democrats denouncing the health care bill. Later, in an interview, he made clear that would only go so far down this road.

“I don’t use the term resistance,” Mr. Brown said. “That was a term I associate with the French underground and people who risked their lives. So I don’t know that that’s a fair, apt metaphor for the latest contretemps over policy.”

“I’m trying to be careful here,” he said. “I know how to throw rhetorical bombs. I don’t do that every day. I’ve learned that you have to pace yourselves. The key is: at the right time, at the right moment for the right purpose.”

John Chiang, the state treasurer who is running for governor, praised Mr. Brown’s maneuvering. “He’s doing it the right way,” Mr. Chaing said. “He’s done a little bit of a dance.”

“My philosophy is to assist where we can and resist where we must,” he said.

Other Democrats said they initially responded to Mr. Trump with a similar posture, but changed after watching him assemble his government. Antonio R. Villaraigosa, a former Los Angeles mayor running for governor, questioned whether it was worth even making an effort with Mr. Trump.

“In a free and open society it’s almost impossible to negotiate with a tyrant, to find common ground with a bully,” he said.

There have been conflicting signals from Washington about how tough Mr. Trump’s policies might be on states like this. The White House approved all three requests from Mr. Brown to declare states of emergency after winter storms caused extensive damage. Still, officials took note of Mr. Sessions’ threat to take away federal funds from sanctuary cities.

“It’s difficult to develop a relationship with someone who has made incessant threats to the well-being of your state from Day 1,” said Mr. de Leon, whose tenure in Sacramento ends next year. “We’re not looking for a fight. But he has made it very clear since the presidential primary what he intends to do.”

Mr. Newsom said that concern about Mr. Trump had already engulfed the race for governor, and argued that he had been tougher on the president than most other Democrats (he declined to name names).

“I have just had two town halls in the last two weeks, and it was all about Trump,” he said. “I will say this as a point of contrast: This is not a time to be silent. This is a time to be firm and bold against this unprecedented threat to the things we hold dear in California.”