Democratic leaders have been running victory laps in the days since they struck a deal with President Trump, over Republican objections, to extend the nation’s borrowing limit and keep the government open for three months.

But new divisions among Democrats show that peril may yet lie ahead for Senate Minority Leader Charles E. Schumer (D-N.Y.) and House Minority Leader Nancy Pelosi (D-Calif.), whose newfound connection with the president has put them in a similar spot as many Republicans this year: working with an unreliable and unpopular partner to attain legislative goals that may never materialize.

Trump’s abrupt overtures to Schumer and Pelosi this week have raised difficult questions for the party out of power about how much to collaborate with a mercurial president whose policies and rhetoric have stirred widespread anger and fear on the left.

A growing number of Democratic lawmakers and activists are voicing worries about getting too close to Trump, whom they have held up as the opposite of what they stand for on issues of race, immigration, the environment and the economy — and whom they hope to campaign against in next year’s midterm elections.

At the same time, party leaders are trying to build on the surprise dynamic that materialized this week in hopes of advancing elements of an agenda that has been largely shut out of the legislative process since Republicans assumed control of the White House and Congress in January.

The challenge of that balancing act is compounded by existing struggles that erupted in the party after last year’s election losses and have yet to settle. While they have stood united against Trump this year, Democrats have also been riven by ideological divisions, competing power centers and the lack of a clear identity or leader.

Now, they are at yet another crossroads.

“Our base is deeply alienated from this president,” Rep. Gerald E. Connolly (D-Va.) said in an interview Friday. “Our base is not saying, ‘Work with him; try to find some common ground.’ ”

“That base,” he added, “will be quite jaded about any overt attempts to make him look good or somehow normalize what we’ve experienced here.”

Connolly, like many Democrats, hopes Trump’s sudden willingness to work with them will pave the way for a legislative deal to help 690,000 young undocumented immigrants brought into the United States as children, who now face an uncertain future after Trump decided this week that in six months, an Obama-era program to protect them will end.

Trump sided with Pelosi and Schumer this week when he backed a three-month extension of the debt ceiling and government funding as part of a package that also offers more than $15 billion in disaster relief funding related to Hurricane Harvey.

Congressional Republican leaders wanted a longer-term deal — in part to avert a December showdown that is likely to give Democrats leverage to usher in a replacement for the Deferred Action for Childhood Arrivals (DACA) program that Trump pledged to end. Republicans had also hoped to avoid voting more than once on raising the nation’s borrowing limit before next year’s midterm elections.

Still, some Democrats are frustrated that party leaders did not demand more in the package that passed this week — notably a more immediate solution to the immigration question.

“I pled with the Democratic leadership not to allow a vote on a continuing resolution on the funding of our government, not to allow a vote on raising the debt limit, if we didn’t bring you with us,” said Rep. Luis V. Gutiérrez (D-Ill.) at a news conference Friday. He later added: “We didn’t prevail.”

In an interview with reporters Friday, Pelosi did not back down from her negotiating tactics. She said she does not think Democratic voters believe that she and Schumer should avoid finding common ground with Trump.

“I make no apology for doing that with the person who is going to sign the bill,” said Pelosi, who was also able to persuade Trump to tweet a reassuring message to young immigrants this week. “It gives you great leverage.”

Others were skeptical.

“Short-term tactics may not serve progressive interests in the long term,” said Norman Solomon, a delegate last year to the Democratic National Convention for Sen. Bernie Sanders (I-Vt.). “I think this whole path of getting chummy with Trump is fraught with land mines and pitfalls, and Trump is an expert at detonating under people’s feet.”

Some Democrats think Trump has warmed to Democrats as a way to punish Republican leaders, with whom he has had troubled relations and with whom he has not achieved any major legislative wins.

For that reason, those Democrats are approaching the president cautiously. They are also reminding themselves of how much they disagree with the ideas that have defined the early months of his presidency.

Those include his proposed ban on entry to the United States by citizens of certain countries, his controversial blaming of both sides after a deadly white supremacist rally in Charlottesville and his rollback of Obama-era environmental policies, as well as his decision to end DACA.

Democrats have used these developments to begin building a case against the president ahead of the 2018 midterms and the 2020 presidential election. But some strategists said the legislative tactics of the minority party in Congress are a separate question from where the party’s center of gravity lies as the next presidential race approaches. Democrats got something at almost no cost in the deal with Trump, some said.

“The Democrats haven’t lost anything. If you can get a deal entirely on your terms, you’d be nuts not to take it just because Trump is on the other side of the table,” said Brian Fallon, who was Hillary Clinton’s presidential campaign press secretary and a former aide to Schumer.

The question of whether cooperating with Trump poses reputational risks for Democrats now or later comes amid echoes of the bitter rift between supporters of Clinton and Sanders during last year’s Democratic primaries.

Those battle lines have re-formed in recent days with the leaking of portions of Clinton’s 2016 memoir, “What Happened,” including a broadside against Sanders for allegedly weakening Democrats and creating an opening for Trump.

“His attacks caused lasting damage, making it harder to unify progressives in the general election and paving the way for Trump’s ‘Crooked Hillary’ campaign. I don’t know if that bothered Bernie or not,” Clinton writes.

Sanders suggested Thursday that the blame lies elsewhere.

“Look, you know, Secretary Clinton ran against the most unpopular candidate in the history of this country, and she lost,” Sanders said during an interview on CBS’s “Late Show” with Stephen Colbert. “And she was upset by that. I understand that.”

In addition to the lingering bitterness from the end of the campaign, some Democrats have also openly questioned the efficacy of their current leaders, including Pelosi. What looks like a wide-open 2020 Democratic primary has left the party without a clear political standard-bearer. Heated intraparty debates have also opened up over whether candidates for office should face litmus tests on abortion and health care.

But when it comes to the first few months of Trump’s presidency, there is far more agreement among Democrats, who have stood forcefully against the president. Still, some have found a way to separate that from the gears of governance.

“I think at the end of the day, if it’s Trump acceding to Democratic demands or Democratic priorities, Democrats believe in government working,” said Neera Tanden, president of the liberal Center for American Progress and a former Clinton aide. “That’s a big difference between us and the other side. People are pragmatic to that extent.”

Asked Friday whether Trump’s agreement with Democrats might become a habit, White House press secretary Sarah Huckabee Sanders said voters expected pragmatism and bipartisanship from Trump. She brushed aside questions about Republican annoyance.

“The most important thing is that the deal got done. The president acted on it, and he worked with Democrats to get it done,” Sanders said. “And I think he’s going to continue to work with whoever is interested in moving the ball forward to help the American people.”

For many unconvinced Democrats, the question that remained unanswered was how long Trump will be interested in working with them. Few are wagering they are at the beginning of a lasting relationship.

“I don’t see it as anything but what’s necessary to get us beyond the moment,” said Rep. James E. Clyburn (D-S.C.), the assistant House Democratic leader. “I don’t see it as anything that is sustained for any relationship going down the road.”

Kelsey Snell and Mike DeBonis contributed to this report.