President Biden signed off Thursday on a bipartisan agreement that would pump hundreds of billions of dollars in new spending into infrastructure projects across the country — handing him, if it passes congressional muster, a significant cross-party achievement and a top goal of his administration.

But Biden immediately pledged to abandon the compromise if Democrats on Capitol Hill do not simultaneously send him a sweeping package of Democratic spending priorities, opposed by most Republicans, to shore up the nation’s social safety net.

“If this is the only thing that comes to me, I’m not signing it,” Biden said of the bipartisan package on Thursday, shortly after triumphantly announcing the deal with Republican and Democratic senators outside the West Wing of the White House. “It’s in tandem.”

The comments underscored the complex legislative path ahead for Biden’s infrastructure agenda, which will force Democratic leaders to keep nervous liberals at bay while attracting enough GOP support to satisfy the president’s push for bipartisanship.

But on Thursday, both sides took a moment for a victory lap. The announcement featured a scene — highly unusual in recent years — of senators from both parties smiling and joking together. It also marked a signal moment for Biden’s insistence, over strong disagreement from many in his own party, that bipartisanship is still possible.

More broadly, Biden has made it clear he believes the central mission of his presidency is to turn the page on the Trump era’s divisiveness and show that democracy can work.

The bipartisan agreement, crafted by Sens. Rob Portman (R-Ohio), Kyrsten Sinema (D-Ariz.) and eight others in the Senate, would spend $973 billion over five years (or $1.2 trillion over eight years). Of that, $579 billion is new spending that was not already allocated through other projects, according to details released by the White House.

The new spending includes $312 billion for transportation projects, $55 billion for water infrastructure and $65 billion for broadband — figures hashed out by the five Democrats and five Republicans who had negotiated for weeks on the package.

That is nowhere near as sweeping as Biden’s own infrastructure measure, which he detailed in April, and it essentially ignores his $1.8 trillion American Families Plan, which focuses on social safety-net programs that Biden characterizes as “human infrastructure.”

“Neither side got everything they wanted in this deal,” Biden said. “That’s what it means to compromise, and it reflects something important, reflects consensus. The heart of democracy requires consensus.”

The group of 10 senators had reached a tentative agreement Wednesday night after marathon negotiating sessions with three top White House officials: Steve Ricchetti, counselor to the president; Louisa Terrell, legislative affairs director; and National Economic Council Director Brian Deese.

The senators stressed that members of both parties had to let go of some much-desired provisions to reach a deal. “We all gave some to get some,” Sinema said. “We are delighted to go back to the Hill and begin earning more support from Democrats and Republicans to get this bill across the finish line.”

As Sinema suggested, the hard part is just beginning. The deal must survive attacks from the right that it is too costly and from the left that it is too meager. Some GOP leaders are also wary of giving Biden any bipartisan win ahead of the 2022 midterms.

Much of the debate will focus on whether the bill will be accompanied by Biden’s “human infrastructure” package, encompassing programs such as paid leave and expanded education funding. If liberals, as seems likely, refuse to support Thursday’s compromise unless it is accompanied by such a bill — and Republicans refuse to support it if it is — that could create a difficult path.

Neither Senate Majority Leader Charles E. Schumer (D-N.Y.) nor Minority Leader Mitch McConnell (R-Ky.) endorsed the bipartisan agreement, although Schumer has said he is generally supportive of its concepts.

Schumer, as he has done for weeks, emphasized Thursday that Democrats are pushing ahead on the Democratic-only “human infrastructure” legislation, which could cost as much as $6 trillion.

“My sales pitch to our whole caucus is, if we don’t have unity, we’re going to get nothing done,” Schumer said. “We’re going to try to do as much bipartisan as we can.”

McConnell quickly took aim at Biden’s insistence that he will only sign the bipartisan bill if Congress also passes the Democrats-only measure.

“It almost makes your head spin — an expression of bipartisanship, and then an ultimatum on behalf of your left-wing base,” McConnell said. “I have no doubt the president is under enormous pressure from some on the left to deliver a laundry list of radical climate demands.”

Sen. Bill Cassidy (R-La.), one of the Republicans backing the bipartisan package, dismissed threats by House Speaker Nancy Pelosi (D-Calif.) to block that package unless the Democrats-only bill passes as well.

If Democrats fail to pass their own bill, “and therefore the American people won’t be able to enjoy the fruits of a bipartisan infrastructure bill which the president has endorsed — boy, those are pretty miserable politics for the speaker going into the midterm, aren’t they?” Cassidy said.

But Biden’s pledge may have been the only way to ensure support from liberals for the compromise. Liberal Democrats have fretted for months that a deal with Republicans would drain momentum from the push to expand spending on social programs and climate change.

Thursday’s deal includes at least $73 billion to bolster the electric grid and provide clean energy, but that falls far short of the multi-trillion-dollar effort sought by some on the left to combat climate change.

Rep. Alexandria Ocasio-Cortez (D-N.Y.) immediately illustrated how hard it may be to get support from liberals, tweeting out a photo of Thursday’s White House announcement and alluding to the fact that all the lawmakers in the picture were White.

“The diversity of this ‘bipartisan coalition’ pretty perfectly conveys which communities get centered and which get left behind when leaders prioritize bipartisan dealmaking over inclusive lawmaking,” Ocasio-Cortez wrote.

Possibly in response to such critiques, Biden in his comments singled out provisions like the replacement of lead pipes throughout the country, which he said would especially help communities of color.

Besides Sinema, Portman and Cassidy, the other lawmakers at the White House were Sens. Susan Collins (R-Maine), Joe Manchin III (D-W.Va.), Lisa Murkowski (R-Alaska), Mitt Romney (R-Utah), Jeanne Shaheen (D-N.H.), Jon Tester (D-Mont.) and Mark R. Warner (D-Va.).

While Sen. Bernie Sanders (I-Vt.) stressed that Democrats were continuing to push their “human infrastructure” bill, members of the bipartisan Senate group were hopeful that Biden’s imprimatur would help soothe progressives.

“The president of United States came out in front of the press and the nation and the world, in a sense, and said he supports this deal,” Warner said. “I’ve never seen a time when a president of either party doesn’t have influence with members of their party. And Joe Biden has enormous, enormous respect on both sides.”

Biden himself argued that lawmakers would support a bill they consider imperfect if it includes much of what they want. “When you ask me what guarantee do I have that I have all the votes I need — I don’t have any guarantee,” Biden said. “But what I do have is a pretty good read over the years of how the Senate and the Congress work.”

The president also suggested that the infrastructure program has significance beyond its specific content.

“One of the underlying questions is, can democracies compete with autocratic enterprises in the 21st Century,” Biden said. “This is a big move toward that, toward being able to compete.” He added, “It also signals to the rest of the world, and to ourselves, that American democracy can deliver.”

The White House listed more than a dozen sources of funding for the package, but offered few specifics Thursday on how those measures would work or how much money they would raise.

The primary financing sources include reducing the “tax gap,” the difference between what the Internal Revenue Service is owed and what it actually collects; repurposing unused federal unemployment aid; and diverting other unspent money from coronavirus relief packages. The White House also said the deal includes an extension of user fees, a “superfund” tax on chemicals and auction proceeds from 5G spectrum sales.

Portman said about $80 billion of unused virus relief money would be redirected to infrastructure spending. “It’s not something that they preferred, but that’s part of the compromise,” Portman said of the White House.

Tax experts have given widely different assessments of how much funding can be raised by increasing IRS enforcement, with estimates varying by hundreds of billions of dollars depending on what policy changes are adopted. Conservatives are particularly uneasy about plans to increase IRS enforcement.

Warner helped push the White House position on funding during the talks, rejecting GOP suggestions to raise the gas tax or impose fees on electric vehicles, two people familiar with the matter said. The White House initially proposed paying for infrastructure with a higher corporate tax rate, but that approach was quickly ruled out by Republicans. The corporate tax hike is likely to be revisited in the separate package.

Senators said aides will spend the next couple of weeks turning the bipartisan agreement into legislative text, which will likely be released when the Senate returns to Washington after a two-week Fourth of July recess. The negotiators will also continue to brief other senators on their proposal.

“I would say over 60 percent of this legislation has, in effect, already been written,” Portman said. “We’re not trying to re-create the wheel here.”

Marianna Sotomayor and Colby Itkowitz contributed to this report.