The breakthrough moment in the negotiations to avoid a second government shutdown came on Sunday when Rep. Nita Lowey Nita Sue LoweyTop House Democrats call for watchdog probe into Pompeo's Jerusalem speech With Biden, advocates sense momentum for lifting abortion funding ban Progressives look to flex their muscle in next Congress after primary wins MORE (D-N.Y.), chairwoman of the House Appropriations Committee, called her Republican counterpart, Senate Appropriations Committee Chairman Richard Shelby Richard Craig ShelbySenate GOP eyes early exit Dems discussing government funding bill into February GOP short of votes on Trump's controversial Fed pick MORE (R-Ala.), and insisted on a meeting the following day.

"I thought it would disintegrate into no agreement. Then I get a phone call from Chairman Lowey and she says the four of us need to get together," recalled Shelby, moments before the Senate passed the deal on Thursday.

ADVERTISEMENT

Also invited to the final discussion were the two senior minority members of the Senate and House spending committees, Sen. Patrick Leahy Patrick Joseph LeahyBattle over timing complicates Democratic shutdown strategy Hillicon Valley: Russia 'amplifying' concerns around mail-in voting to undermine election | Facebook and Twitter take steps to limit Trump remarks on voting | Facebook to block political ads ahead of election Top Democrats press Trump to sanction Russian individuals over 2020 election interference efforts MORE (D-Vt.) and Rep. Kay Granger Norvell (Kay) Kay GrangerGOP women's group rolls out six-figure campaign for Ernst Bottom line Helping our seniors before it's too late MORE (R-Texas).

Shelby said he was skeptical of getting a deal after negotiations derailed Saturday, but he was willing to give it a try.

At a leadership staff meeting Saturday, Democrats had insisted on capping the number of beds available to Immigration and Customs Enforcement (ICE) to detain immigrants, according to an administration official.

That cap was pushed hard by Rep. Lucille Roybal-Allard Lucille Roybal-AllardHispanic Caucus asks for Department of Labor meeting on COVID in meatpacking plants Democrats may bring DHS bill to House floor Texas Democrat proposes legislation requiring masks in federal facilities MORE (D-Calif.), who had never chaired an appropriations subcommittee before taking the helm of the Homeland Security Appropriations Subcommittee last month.

On Sunday, Speaker Nancy Pelosi Nancy PelosiPelosi: Trump hurrying to fill SCOTUS seat so he can repeal ObamaCare House lawmakers reach deal to avert shutdown Centrist Democrats 'strongly considering' discharge petition on GOP PPP bill MORE (D-Calif.) was traveling up and down the West Coast — Los Angeles, San Diego and San Francisco — fundraising and holding other meetings, while keeping close tabs on the talks.

An early riser, Pelosi phoned Roybal-Allard at 6:30 a.m. PST — 9:30 a.m. in D.C. — when she and Lowey were in the Capitol leading a conference call with other Democratic conferees. Roybal-Allard put Pelosi on speakerphone for an update on the talks.

ADVERTISEMENT

Roybal-Allard, concerned with the Trump administration breaking apart immigrant families, wanted a cap on detention beds for noncriminal immigrants without legal status who were already in the country.

The White House and its Republican allies balked. They complained that Democrats were raising a new issue at the last minute and that the cap proposal would leave violent criminals on the streets of America.

Shelby wasn’t sure the impasse over ICE beds could be solved, but Lowey insisted it could be, giving him hope for a resolution.

"We don't need to waste our time, but I'm willing to meet you anywhere, at least 50-50,” Shelby said he told Lowey on Sunday.

"She said, ‘We need to do this,’ and I said, 'We do, but can we?' I think that was a pivotal time,” Shelby recalled.

Lowey asked him to set up a meeting the following afternoon, on Monday.

Shelby then invited her, Leahy and Granger to meet in his Appropriations Committee suite on the first floor of the Capitol, setting the stage for a negotiation that would be much different than what preceded.

“The key moment was when the four corners got together. That was the key moment. The key moment was that, I believe, there was a realization that [the effort] was too important to fail,” said Sen. Jon Tester Jonathan (Jon) TesterPence seeks to boost Daines in critical Montana Senate race This World Suicide Prevention Day, let's recommit to protecting the lives of our veterans Filibuster fight looms if Democrats retake Senate MORE (D-Mont.), one of several members of the Senate-House conference committee who were left out of the final meetings.

Shelby, Lowey, Leahy and Granger are all veterans of the Senate and House appropriations panels and have negotiated many deals over the years.

In addition to being the top-ranking Democrat on the Appropriations Committee, Leahy is also the longtime former chairman and now ranking member of the State Department and Foreign Operations Subcommittee on the spending panel.

It was a fortuitous coincidence, because Lowey and Granger both served together as members of the state and foreign ops subcommittee in the House, and have often worked together with Leahy on issues under their shared jurisdiction.

The feeling among the senior negotiators was that the more-junior members like Roybal-Allard, who had less experience cutting big deals, were getting in the way.

Tester later acknowledged that the 17-member conference committee was becoming unwieldy.

“It clutters it up. You know how senators are, everybody wants to talk for 15 minutes or 20 minutes at a time,” he said.

Another member of the conference committee said appropriators have a “mindset to trying to do as much as you can to get what you want but understand you have to reach a conclusion” because they have to pass 12 spending bills every year.

“It came down to four pretty damn seasoned people,” the source added. “Collectively they’ve done this hundreds of times.”

So Shelby and Lowey wanted to limit the talks to the most-experienced conferees who had cut the most deals.

President Trump Donald John TrumpOmar fires back at Trump over rally remarks: 'This is my country' Pelosi: Trump hurrying to fill SCOTUS seat so he can repeal ObamaCare Trump mocks Biden appearance, mask use ahead of first debate MORE had given Shelby the green light to come up with a compromise, knowing it wouldn’t give him the $5.7 billion he wanted. But the president was preparing to supplement whatever Congress appropriated with a national emergency declaration, said sources familiar with the talks.

“He gave us some latitude to negotiate and indicated strongly that he wanted us to do it, in other words [find] a legislative solution,” Shelby said, summarizing a conversation he had with Trump on Thursday.

When Shelby, Lowey, Leahy and Granger met in Shelby’s office at 3:30 p.m. on Monday, the mood was improved. They were starting to make progress but still had a ways to go.

As the meeting started to wrap up ahead of a 5:30 p.m. vote, Leahy suggested they meet again at 6 p.m. in his Capitol hideaway, which shares a balcony with the Speaker’s office and a fabulous view of the National Mall and Washington Monument.

The advantage of meeting there: It’s the halfway point between the Senate and House chambers, an important symbolic gesture at a time when the negotiators were trying to reach what they knew had to be a 50-50 split.

They also knew that failure was not an option. If they couldn’t reach a deal, then either their colleagues would pass a yearlong stopgap measure — essentially throwing away all the work they had poured into the seven unfinished spending bills — or Congress would careen into another partial government shutdown just three weeks after the previous one ended, on Jan. 25.

There were also signs that Pelosi was beginning to soften her stance on leashing ICE.

She phoned Lowey and Roybal-Allard on Monday and the three agreed to drop that demand in favor of less-contentious provisions designed to put limits on ICE’s apprehension and deportation of immigrants with no criminal records.

Senate Majority Leader Mitch McConnell Addison (Mitch) Mitchell McConnellPelosi: Trump hurrying to fill SCOTUS seat so he can repeal ObamaCare Senate GOP aims to confirm Trump court pick by Oct. 29: report Trump argues full Supreme Court needed to settle potential election disputes MORE (R-Ky.) also signaled he was eager for a deal, warning GOP colleagues in a meeting the previous week that if a deal failed to materialize, they would be facing the unpalatable choice of voting for another stopgap or plunging into another shutdown.

He reiterated that message when Republican senators gathered for lunch Tuesday to discuss the outlines of the agreement. No one spoke up in opposition, according to sources in the room.

When the top four negotiators reconvened in Leahy’s hideaway at 6 p.m. on Monday, they didn’t get right down to business but instead chit-chatted a while about personal interests, establishing a friendly mood ahead of what they knew would be difficult decisions.

“We’re all good friends,” Leahy said. “Congresswoman Granger knows I do a lot of photography. She taught photography in high school; we talked about that. It was like the old days. We start talking about, my kid went to this school or that."

After being deadlocked just a day before, the talks were fast gathering momentum and it became clear that the group could reach a deal if they took a short break and then huddled again at 8 p.m.

Leahy said someone in the room observed how long they had all known each other and remarked, “If we four can’t work it out, who the heck can?”

It became clear that Trump would lose on the border barrier funding, but Democrats would have to back down on their proposal to cap the number of ICE beds at 16,500.

Instead, the legislation would provide funding authority for as many as 45,000 beds and allow the administration flexibility to shift money to provide as many as 52,000 beds. Whether that higher number can be achieved, however, depends on finding money to transfer.

Less than an hour after meeting for a third time, they emerged from Leahy’s hideaway to announce they had a deal "in principle."

As details leaked out, concerns began to grow among conservatives who were outraged the agreement provided just $1.375 billion for new border barriers, and would extend fencing by only 55 miles.

Fox News host Sean Hannity ripped it as a “garbage compromise” while conservative author Ann Coulter mocked it as the “Yellow New Deal,” conflating the color known for symbolizing cowardice with the House liberals’ "Green New Deal" plan to address climate change, which Republicans have widely panned.

Trump was also upset, telling television cameras at a Cabinet meeting Tuesday, “I’m not happy.”

But after McConnell explained to him the details of the deal in a Tuesday phone call and Shelby followed up with a Wednesday call, Trump began to soften.

“I went over a lot of stuff — $23 billion in total for border security and new walls,” Shelby said. “We had a nice conversation. He seemed to be very interested. I didn’t recall him saying he was unhappy.”

The president was pleased when the lawmakers told him he could emphasize the $23 billion provided in total for border security — which came close to the $25 billion that experts estimated the border wall would cost at the start of Trump’s term.

He trumpeted what he began to see as good news in two Wednesday morning tweets.

“Looking over all aspects knowing that this will be hooked up with lots of money from other sources,” he tweeted. “Will be getting almost $23 BILLION for Border Security. Regardless of Wall money, it is being built as we speak!”

Even so, Trump left Republican lawmakers in suspense about whether he would sign the bill as White House staff poured through more than 1,000 pages of the legislation.

One of the biggest concerns of the White House was if the $1.375 billion in border fencing could be supplemented with a national emergency declaration.

A major question was whether the president would suffer an embarrassing setback if Democrats managed to pass a privileged resolution of disapproval through the House and Senate blocking the emergency declaration.

It was clear Trump could sustain a veto, but losing a vote on the Senate floor would look bad and show divisions in the Senate GOP conference over the president’s decision.

The Washington Post reported earlier this month that McConnell privately warned Trump in a meeting at the White House on Jan. 29 not to declare an emergency to fund the wall.

McConnell, however, assured Trump on Thursday that he would back the emergency declaration.

"I just heard there was a lot of, about two hours of intensive back and forth discussions … between the White House and the leader's office," Sen. John Cornyn John CornynThe Hill's Campaign Report: GOP set to ask SCOTUS to limit mail-in voting Liberal super PAC launches ads targeting vulnerable GOP senators over SCOTUS fight Senate GOP faces pivotal moment on pick for Supreme Court MORE (R-Texas), a member of McConnell’s leadership team, remarked to reporters Thursday.

Cornyn said the discussion centered on whether Trump would sign the bill and under what circumstances.

McConnell then went to the floor shortly after 3 p.m. on Thursday to announce Trump would sign the legislation into law and declare a national emergency, which the GOP leader said he would back.

Pelosi had what looked like a tough job selling her caucus on the deal during a meeting Wednesday.

“In legislation, it is a process, and don’t fight every fight as if it is the last fight,” Pelosi said in the meeting. “We have other fights to make and we have to be as strong as possible going into them.”

The pitch didn’t get everyone on board.

A notable list of liberal freshmen — including Reps. Alexandria Ocasio-Cortez Alexandria Ocasio-CortezHouse passes bill to avert shutdown Trump attacks Omar for criticizing US: 'How did you do where you came from?' The Memo: Dems face balancing act on SCOTUS fight MORE (D-N.Y.) and Ilhan Omar Ilhan OmarOmar fires back at Trump over rally remarks: 'This is my country' Trump attacks Omar for criticizing US: 'How did you do where you came from?' Democrats scramble on COVID-19 relief amid division, Trump surprise MORE (D-Minn.) — opposed the bill when it hit the floor Thursday night. They joined a handful of other liberals and border Democrats who said that for communities directly affected, there will be no practical distinction between Trump’s wall and the Democrats’ fencing.

But in the end, an overwhelming majority of House Democrats sided with Pelosi, moving the bill to an easy 300-128 vote in the lower chamber, and advancing the package to Trump’s desk.

The president announced Friday that he had issued an emergency declaration. He is expected to sign the border legislation later on Friday.

Jordain Carney and Mike Lillis contributed.