The three Democratic lawyers met over dinner in a cavernous hotel in Fort Lauderdale, Fla., picking at seafood as they discussed how to take on President Trump: Eric T. Schneiderman, the attorney general of New York; Josh Shapiro, his counterpart in Pennsylvania; and Xavier Becerra, a former congressman who had been sworn in as attorney general of California only a day earlier.

Unrecognized so far from home, and little known to one another, the men spent a Wednesday evening late in January discussing a range of White House policies that might unsettle their states, including a mass deportation of unauthorized immigrants.

They never anticipated that a live-fire test of their teamwork would come less than 48 hours later.

Mr. Trump’s Jan. 27 decree on immigration, shutting off entry to the United States from seven overwhelmingly Muslim countries and halting refugee admissions, left states and cities scrambling to respond. Amid mounting protests and emotional scenes of disorder at American airports, it offered a galvanizing first challenge for a gang of Democratic attorneys general who have vowed to check the power of the White House.

In interviews, more than a dozen Democratic attorneys general, governors and party operatives detailed a week of frenzied litigation, late-night and early-morning phone calls and text messages, and strategies devised on airplanes and at sporting events. All told, Democrats say, the legal onslaught against Mr. Trump was a crystallizing moment for the party’s attorneys general — and a model for how to stall or unwind the administration policies they find most offensive.

Mr. Schneiderman, a former state senator from Manhattan who is in his second term as attorney general, called the travel ban a “first test” of the Democratic legal apparatus under Mr. Trump.

“If they follow through on campaign promises as outrageous as a Muslim ban, then we do have a serious challenge to our constitutional structure,” Mr. Schneiderman said.

The immigration order spurred swift legal actions from five states in four federal courts, and for the most part they adopted a common strategy. With the attorneys general and their aides frequently trading notes, three states — New York, Massachusetts and Virginia — intervened on behalf of individuals stopped at airports. All three cited the state’s interest in protecting students and faculty members at public universities.

A fourth attorney general, Bob Ferguson of Washington State, took a different approach, suing Mr. Trump on behalf of the state itself. He said he spoke with a number of colleagues last week to invite them to join his riskier plan, but initially found only one taker, Lori Swanson of Minnesota.

It was Mr. Ferguson’s suit that won the biggest victory: a federal judge’s ruling on Friday that froze, at least temporarily, the carrying out of a travel ban. Mr. Trump’s administration has filed an appeal before the United States Court of Appeals for the Ninth Circuit, which is set to hold a hearing on Tuesday.

The matter is likely to end up before the Supreme Court.

The number of states opposing Mr. Trump’s order in court may continue to grow: On Monday, Attorney General Doug Chin of Hawaii filed a motion to join Mr. Ferguson’s suit. And 16 of Mr. Ferguson’s colleagues — including Mr. Schneiderman, Mr. Shapiro and Mr. Becerra — filed an amicus brief with the appeals court supporting his action.

Hector Balderas, the New Mexico attorney general, said he had directed aides to identify areas where Trump administration policies could damage New Mexico.

He described the attack on Mr. Trump’s immigration order as a blueprint for state attorneys general who aim to rein in the White House.

“It does seem that we are becoming, potentially, the fourth branch of government,” Mr. Balderas said in an interview.

A Looming Fight

Even before Mr. Trump’s directive, Democratic attorneys general were gearing up to play a larger role in national politics. With Republicans in control of the White House and Congress, Democrats have increasingly looked to the states both to challenge Mr. Trump’s policies and to enforce federal regulations, including on business and the environment, that his administration may ignore.

Several state attorneys general have cited as an inspiration the long-running legal war waged against the Obama administration by Republican attorneys general, who derailed key White House policies on immigration and nearly voided the Affordable Care Act.

While Mr. Trump was being sworn in last month, three up-and-coming Democratic attorneys general — Mr. Balderas, Mr. Schneiderman and Maura Healey of Massachusetts — joined a conference of wealthy political donors in South Florida to deliberate over the party’s future. Ms. Healey said there appeared to be an “awakening” among Democratic leaders about the significance of party leaders in the states.

Chris Jankowski, a Republican strategist who was an architect of his party’s efforts to elect formidable attorneys general over the past decade, said Democratic attorneys general were “clearly poised to emerge as a check on the Trump administration, just as their Republican colleagues did for eight years.”

Mr. Jankowski, a lawyer, said Democratic attorneys general would probably rely heavily on the Constitution’s civil rights protections, much as Republicans leaned on constitutional limits on federal economic power.

“State attorneys general are now permanent pieces on the chessboard of national policy development and implementation,” Mr. Jankowski said. “And they are not mere pawns.”

On the last Friday in January, many of those officials had gathered in Fort Lauderdale for a conference of the Democratic Attorneys General Association, a group that helps raise money for their campaigns.

Normally a combination of dry panel discussions and partisan strategizing, the event had a distinctly ominous tone in the shadow of Mr. Trump’s inauguration, several attendees said: At a private luncheon, Representative Debbie Wasserman Schultz, the former Democratic Party chairwoman, exhorted the group to see itself as a last line of defense.

Ms. Wasserman Schultz, in an interview, said she asked the attorneys general to work with congressional Democrats to combat “an administration that has no regard for the law or the Constitution.”

The White House issued its immigration decree the same day.

The Frantic Response

For the Democrats gathered in Fort Lauderdale, the order was like a starter’s pistol. Racing back to their home states, they began a loosely coordinated effort to challenge Mr. Trump in court.

Mr. Ferguson landed in Seattle at noon Saturday, Jan. 28, amid growing airport protests. After rushing home and conferring with staff members, he began calling up Washington-based corporations — including Expedia and Amazon — to enlist them in a lawsuit.

If some of his colleagues were caught off guard, Mr. Ferguson, a cerebral former state chess champion, said his office had been bracing for just such an action. “We’d been anticipating that the president would execute an executive order along these lines,” he said. “We’d been having internal communications about it.”

Mr. Ferguson told his staff that he viewed Mr. Trump’s policy as thoroughly unconstitutional. An effective lawsuit, he said, should leave the order in tatters.

His colleagues across the country, however, quickly settled on a narrower legal strategy: In New York and Massachusetts, Mr. Schneiderman and Ms. Healey developed plans to assail the Trump order based on its impact on specific state institutions, like public hospitals and universities where faculty members and students would be affected.

Ms. Healey, a former Harvard basketball player, said she and her senior aides spoke with top officials at the University of Massachusetts, M.I.T. and her alma mater as they developed their suit. In a bipartisan gesture, she also resolved to bring her state’s Republican governor, Charlie Baker, on board. The two spoke before the suit was filed, Ms. Healey said, and Mr. Baker issued a statement backing the challenge.

Though many national Republicans declined to criticize Mr. Trump, Ms. Healey said the image of solidarity across party lines had been important in her state. “This goes to the heart of who we are,” she said.

In the suburbs of Philadelphia on the same Saturday, Mr. Shapiro, a former county commissioner sworn in as attorney general just 11 days earlier, began rounding up counterparts to issue a joint statement of opposition to the executive order while he was coaching his 7-year-old son’s basketball game.

Tapping away on his iPhone, Mr. Shapiro circulated a draft to colleagues including Mr. Schneiderman, Mr. Becerra and Ms. Healey before appealing to the full group of Democratic attorneys general to endorse it. Democratic legal officers from 16 states and the District of Columbia signed the letter; attorneys general from six states, including deep-red Mississippi and Kentucky, did not.

In the statement, the signers pledged to “use all the tools of our offices to fight this unconstitutional order and preserve our nation’s national security and core values.” Mr. Shapiro said he “personally worked the phones” to organize the group message.

The Struggle in Court

Over the first weekend Mr. Trump’s executive order was in effect, groups like the American Civil Liberties Union charged into court and won temporary restraining orders blocking key parts of it.

But Mr. Ferguson filed the first and broadest state lawsuit on Monday, Jan. 30, with a far more sweeping complaint depicting the executive order as an unlawful assault on Washington businesses and communities.

Each day brought new legal actions by the states: On Tuesday, Ms. Healey announced that Massachusetts would join a lawsuit backed by the A.C.L.U. involving plaintiffs flying through Logan International Airport in Boston. Mr. Schneiderman announced a similar approach in New York. Throughout the week, Attorney General Mark R. Herring of Virginia filed a flurry of legal actions aimed at bolstering the claims of people detained at Dulles International Airport, and challenging the conduct of federal immigration officers there.

Yet rather than demonstrating weakness, the diffuse nature of the Democratic legal response ended up working to the state attorneys general’s advantage, effectively allowing Mr. Trump’s foes to test multiple strategies before multiple federal judges.

And when the anti-Trump lawyers faced one setback in court on Friday, as a federal judge in Boston declined to extend a decision suspending parts of the travel ban, that disappointment was quickly overshadowed by Mr. Ferguson’s victory in Seattle.

“All of us cheered,” Ms. Healey said, recalling the news of the ruling.

Some did more than cheer: One group, including Mr. Shapiro, Mr. Schneiderman and Ms. Healey, marshaled support for a “friend of the court” brief supporting Mr. Ferguson as he heads into protracted litigation.

Mr. Trump’s administration has appealed the Seattle judge’s ruling, and the states face a long legal battle with the federal government.

But in a reflection of the power states have to thwart his agenda, Mr. Trump spent the weekend raging on Twitter that an individual court ruling could stop the whole executive branch in its tracks.

“What is our country coming to,” he wrote, “when a judge can halt a Homeland Security travel ban and anyone, even with bad intentions, can come into U.S.?”