WASHINGTON — Congressional negotiators announced an agreement late Monday to prevent a government shutdown and finance construction of new barriers along the U.S.-Mexico border, overcoming a late-stage hang-up over immigration enforcement issues that had threatened to scuttle the talks.

Republicans were desperate to avoid another bruising shutdown. They tentatively agreed to far less money for President Donald Trump’s border wall than the White House’s $5.7 billion wish list, settling for a figure of about $1.4 billion, according to a senior congressional aide.

“We reached an agreement in principle,” said Senate Appropriations Committee Chairman Richard Shelby, R-Ala., appearing with a bipartisan group of House and Senate lawmakers who concurred.

“Our staffs are just working out the details,” said House Appropriations Committee Chairwoman Nita Lowey, D-N.Y.

Details won’t be officially released until Tuesday, but the pact came in time to alleviate any threat of a second partial government shutdown this weekend.

Shelby had earlier pulled the plug on the talks over Democratic demands to limit immigrant detentions by federal authorities, but Democrats yielded ground on that issue in a fresh round of talks on Monday.

Asked if Trump would back the deal, Shelby said, “We believe from our dealings with them and the latitude they’ve given us, they will support it. We certainly hope so.”

Trump traveled to El Paso, Texas, for a campaign-style rally Monday night focused on immigration and border issues. He has been adamant that Congress approve money for a wall along the Mexican border, though he no longer repeats his 2016 mantra that Mexico will pay for it.

Democrats carried more leverage into the talks after besting Trump on the 35-day shutdown but showed flexibility in hopes on winning Trump’s signature. After yielding on border barriers, Democrats focused on reducing funding for detention beds to curb what they see as unnecessarily harsh enforcement by Immigration and Customs Enforcement, or ICE.

The border debate got most of the attention, but it’s just part of a major spending measure to fund a bevy of Cabinet departments. A collapse of the negotiations could imperil budget talks going forward that are required to prevent steep spending cuts to the Pentagon and domestic agencies.

The negotiations hit a rough patch Sunday amid a dispute over curbing ICE, the federal agency that Republicans see as an emblem of tough immigration policies and Democrats accuse of often going too far.

A House Democratic aide said Republicans had already agreed to funding cuts that would require ICE to ramp down the number of detention beds to a range of 34,000-38,500 by the end of the year. ICE currently detains about 49,000 immigrants on average per day.

But a proposal to cap at 16,500 the number of detainees caught in areas away from the border — a limit Democrats say is aimed at preventing overreach by the agency — ran into its own Republican wall.

“ICE is being asked to ignore the laws that Congress has already passed,” said agency Deputy Director Matt Albence on a media call organized by the White House.

According to ICE figures, 66 percent of the nearly 159,000 immigrants it reported detaining last year were previously convicted of crimes. Reflecting the two administration’s differing priorities, in 2016 under President Barack Obama, around 110,000 immigrants were detained and 86 percent had criminal records.

Few convictions that immigrants detained last year had on their records were for violent crimes. The most common were for driving while intoxicated, drugs, previous immigration convictions and traffic offenses.

Trump met Monday afternoon with top advisers in the Oval Office to discuss the negotiations. He softened his rhetoric on the wall but ratcheted it up when alluding to the detention beds issue.

“We can call it anything. We’ll call it barriers, we’ll call it whatever they want,” Trump said. “But now it turns out not only don’t they want to give us money for a wall, they don’t want to give us the space to detain murderers, criminals, drug dealers, human smugglers.”

The recent shutdown left more than 800,000 government workers without paychecks, forced postponement of the State of the Union address and sent Trump’s poll numbers tumbling.

As support in his own party began to splinter, Trump surrendered after the shutdown hit 35 days, agreeing to the current temporary reopening without getting money for the wall.

The president’s supporters have suggested that Trump could use executive powers to divert money from the federal budget for wall construction, though he could face challenges in Congress or the courts.