WASHINGTON — President Trump and congressional leaders remained far from an agreement over his demand for money for a border wall after another White House meeting, an impasse that has blocked funding for many government operations and forced a partial shutdown now two weeks old.

Sen. Charles E. Schumer of New York, the Senate Democratic leader, said after the talks in the privacy of the White House Situation Room that Trump told the group he would be willing to keep the affected government agencies closed for “months or even years.”

“I did say that, absolutely I said that,” Trump told reporters later. “I don’t think it will, but I am prepared.” He added, “I hope it doesn’t go on even beyond a few more days.”

The Democrats insisted that negotiating over border security could only follow after funding and opening the quarter of the government that is now shuttered.

“We really cannot resolve this until we open up government,” said new House Speaker Nancy Pelosi (D-San Francisco). “We made that clear to the president.”

Trump and top Democrats each put the burden on the other to end the stalemate. Neither appeared to feel much pressure from their respective supporters to give ground even as roughly 450,000 federal employees had to work without pay and an additional 380,000 are unpaid on furlough. But cracks have opened in support among Republicans in Congress for the president’s hard line.

Trump, speaking to reporters in the Rose Garden after the meeting, expressed more optimism than Pelosi and Schumer about resolving the shutdown impasse, possibly through meetings among aides that will continue through the weekend. Even so, he refused to budge from his demand, calling conditions at the border “a dangerous, horrible disaster.”

“We’ve done a great job,” he said. “But you can’t really do the kind of job we have to do unless you have a major, powerful barrier.”

He added, “We won’t be opening [the government] until it’s solved.”

Trump suggested that he could declare a national emergency to build a wall unilaterally without congressional approval. “I may do it,” he said. “We could call a national emergency and build it very quickly. That’s another way to do it. But if we can do it through a negotiated process, that’s better.”

In recent days, White House aides had signaled openness to a compromise offering Democrats legal protections for so-called Dreamers, young undocumented immigrants who were brought to the United States as children, in exchange for more wall funding. But Trump, who has contradicted his aides several times, has not suggested such a trade, and Democrats, now holding the leverage of their new House majority, have ruled it out.

As the shutdown has stretched on, Trump has dug in more firmly. Though Vice President Mike Pence complained this week that Democrats never responded to him over the holidays about a proposal to reduce the funding demand to about $2.5 billion for wall construction, the president subsequently scoffed at the notion that he’d accept that amount — he blamed “fake news” for mischaracterizing his position — and publicly stuck to his demand for $5.6 billion.

Democratic leaders also stuck to a hard line.

Late Thursday, hours after her election as speaker, Pelosi reiterated to reporters that a wall between countries is “an immorality.” Asked whether Democrats would even give Trump a dollar for a border wall, she responded: “A dollar? Yeah. One dollar.”

She spoke after House Democrats, newly in charge of the chamber after eight years of Republican control, passed measures to reopen the government and to approve $1.3 billion for border security funding that explicitly ruled out spending on a wall.

But the Senate, which approved a similar proposal just over two weeks ago when Republicans assumed Trump would go along, won’t consider the two House bills. Wary of the White House’s mixed signals, Senate Majority Leader Mitch McConnell (R-Ky.) has said the Senate won’t vote on any proposal until it’s clear Trump will sign it.

When Trump addressed reporters after the meeting with Democrats, McConnell was conspicuously missing among the Republican congressional leaders who flanked the president in the White House Rose Garden. A spokesman for McConnell said he would have attended had he been asked.

At one point last month before the shutdown, Sarah Huckabee Sanders, the White House press secretary, seemed to suggest Trump was backing off his wall money demand altogether, saying that he would be able to find the $5 billion he wanted in other government accounts.

Following a backlash from supporters including conservative pundits Rush Limbaugh and Ann Coulter, who criticized Trump as having caved on the issue, the president reversed course and said no to the package approved unanimously by the Senate, forcing the shutdown that began Dec. 22.

Trump has attempted to put pressure on Democrats by claiming there is an ongoing “humanitarian crisis” at the border because of a wave of illegal immigrants, as well as an unsubstantiated influx of terrorists and criminals.

In his remarks to reporters, Trump falsely said his administration had “built a brand-new wall in San Diego.” The border barriers there were first built in the 1990s. Customs and Border Protection has been upgrading some fencing, including a long-planned 14-mile stretch in western San Diego County on which construction began in June. Democrats have already agreed to appropriate money for that project and similar ones.

Trump, who now says a barrier could be of steel bars or fencing, disputed a reporter’s suggestion that he’d promised during his campaign that he would build a wall of concrete. He had, however, at one point telling campaign supporters, “No windows, no nothing — precast concrete going very high.” The other day, he tweeted that “An all concrete Wall was NEVER ABANDONED.”

Speaking of the Obama-era program for Dreamers, Deferred Action for Childhood Arrivals, Trump also falsely said that President Obama, when he signed the executive order to defer deportations for about 700,000 young immigrants, “admitted” that “this isn’t going to work.” He implied that Obama agreed with him that the order exceeded the president’s authority. Obama did not say anything of the sort, but defended DACA’s legality even as he acknowledged that executive authority had limits.

On Friday, just before resuming talks with Democrats, Trump sent a letter to all members of Congress with information that his Homeland Security secretary, Kirstjen Nielsen, had presented days earlier to congressional leaders. Pelosi and Schumer, Trump wrote, “did not want to hear the presentation at the time.”

Trump argued that “it is essential that we make decisions based upon the facts on the ground — not ideology and rhetoric — and that we listen to the law enforcement personnel on the front lines.”

While Trump and congressional allies believe that fighting for border wall funding is a political winner with their party’s base, a few Republicans facing difficult reelection bids in competitive states in 2020 are signaling opposition to the prolonged shutdown.

Polling so far has shown that the general public blames Trump and the Republicans for the shutdown more than they blame congressional Democrats. And spending taxpayer money on a border wall is an unpopular idea with most Americans.

A nonpartisan survey last month by Quinnipiac University, for example, found that voters nationwide opposed shutting down the government over money for the wall by nearly 2 to 1. The same polls also show, however, that the wall remains popular with Trump’s core supporters, which is the audience the president has consistently focused on.

Colorado Sen. Cory Gardner, perhaps the most vulnerable Republican senator for 2020, was the first to call for reopening the government and leaving the fight over border wall funding for later.

“We can pass legislation that has the appropriations number in it while we continue to get more, but we should continue to do our jobs and get the government open,” Gardner said Thursday, referring to the amount for border security that Democrats have already agreed to.

Sen. Susan Collins (R-Maine), who also could face a tough reelection battle next year, staked out a similar position.

In the House, seven moderate Republicans voted with Democrats on Thursday night in support of the spending package to reopen the government. Five of them also backed the separate bill funding the Department of Homeland Security that did not include money for the wall.

One of the Republican defectors, Rep. Will Hurd, represents a sprawling Texas district that includes 41% of the nearly 2,000-mile southern border with Mexico. He has steadfastly opposed construction of a wall, and was reelected in November after a tough campaign in which he emphasized that position.

Rep. John Katko (R-N.Y.) said after the vote that he supports border security but not at the cost of continuing a shutdown. “I remain increasingly frustrated by the inaction of both sides in Congress on this issue,” he said.

“Still, a government shutdown is a costly and unnecessary maneuver that does not help resolve Congress’ failure to act.”

Friday’s White House meeting came on the second day of the new Congress, quickly putting an end to the hopes for bipartisanship expressed by both Republicans and Democrats on Thursday.

Separately, Republicans expressed outrage after newly elected Rep. Rashida Tlaib (D-Mich.) told progressive allies Thursday night that she came to Washington to “impeach the mother—.” Democrats were privately upset with the remark as well, as Pelosi and other party leaders have sought to mute talk of impeachment at least until special counsel Robert S. Mueller III releases his report.

Trump called Tlaib’s remarks “disrespectful” to the country, adding, “I think she dishonored herself and she dishonored her family.” Trump also said that Pelosi, in the White House meeting, told him that Democrats were “not looking to impeach” him.

On Twitter, Pelosi’s spokesman said, “Speaker Pelosi made clear that today’s meeting was about reopening government, not impeachment.”