Mr. Chin, 50, a deep-voiced career litigator who was appointed to his post, rather than elected, has shown an appetite for challenging Mr. Trump in recent weeks. At a meeting between Mr. Trump and state attorneys general last week in Washington, Mr. Chin pressed Mr. Trump to defend the thinking behind his attempts to crack down on travel from the Middle East.

Mr. Trump replied by asking if Mr. Chin was among the attorneys general who had sued over his travel ban, and then said he was trying to “make America safe,” according to Mr. Chin and two other people who were present for the meeting.

Mr. Chin said the president had also acknowledged to the group that “a lot of us wouldn’t like how he was approaching that.”

A spokesman for the White House did not respond to a request for comment on the Hawaii and San Francisco cases.

Even amid the multiplying legal challenges to Trump administration policies, both actions stand out for their aggressive approach. While many mayors have denounced Mr. Trump’s threat to withhold federal funding from cities on the basis of immigration policy, they have also largely declined to take pre-emptive action against the presidential order, pledging to do so in the event that he actually carries out his threat.

In San Francisco on Wednesday, the city attorney, Dennis Herrera, argued that a district court should prevent Mr. Trump from even trying to enforce his order while the city challenges its legality. Mr. Herrera said that because the city budget relies on federal funding, San Francisco could not develop a realistic spending plan “under a cloud of uncertainty and a budgetary sword of Damocles.”