WASHINGTON (AP) — Joe Biden wasn’t progressives’ first choice for the White House in 2020. And he wasn’t their second or third, either.

But defying expectations, liberal Democrats have emerged as the president’s most loyal allies in Congress during his first two years in office, helping to pass a massive COVID-19 relief package, a historic investment in American infrastructure and billions of dollars to combat climate change.

Their alliance was as fruitful as it was unlikely. And it could soon be put to the test.

Democrats are bracing for losses in Tuesday’s elections that could cost them their majorities in the House and Senate, an outcome certain to fuel questions about the party’s direction as Biden considers another run for the White House. Republicans, bullish on their chances of winning back power, are preparing an onslaught of investigations into Biden’s administration and are certain to try and unravel his legislative achievements.

The dynamic between Biden and the liberal flank of his party is one that lawmakers insist will end up uniting Democrats behind Biden, even as some openly say they don’t want him to run for reelection and others complain the president is too prone to compromise.

“The White House is going to need allies to defend the president against the bogus investigations that Republicans may try to launch,” California Rep. Ro Khanna, a former co-chair of Bernie Sanders’ 2020 presidential campaign, said in an interview. “The White House is going to need Dems to be defending the White House’s economic record.”

The movement of progressives into the Biden camp came against long odds.

They are separated by generations and ideologies, with the 79-year-old Biden — a creature of the consensus-driven Senate who has reminisced fondly about how he was able to work even with segregationists — hailing from a party establishment often scornful of younger lawmakers of color who want bold stands on climate change, racial justice and other issues.

But once Biden emerged triumphant from the Democratic primaries and the general election in 2020, he sought party unity, forming a joint task force with the Sanders campaign to craft an agenda.

The result was a Biden wish list that looked much like the left’s: sweeping COVID-19 aid, tax credits for families, free community college, universal child care, public works spending, policies to address climate change.

The White House also took care to nurture relationships with the Democrats who could have been their noisiest critics.

In the past year, either Biden or senior White House aides met with members of the progressive caucus at least a half-dozen times, most notably when the president called directly into a gathering of the group just before the infrastructure vote last November. Biden has appeared alongside House progressives on at least seven trips to their districts in September and October.

The caucus gets plenty of attention from elsewhere in the administration, with at least 10 Cabinet members or agency heads meeting with the progressives in the past year, according to a White House official.

Its legislative affairs office assigned Alicia Molt-West, a former aide to Rep. Mark Pocan, D-Wis., to be its primary liaison to the Congressional Progressive Caucus, and she checks in almost every day. The leader of that caucus, Washington Rep. Pramila Jayapal, has had a direct line to the senior-most levels of the White House, notably chief of staff Ron Klain, and that empowered her and expanded her influence among other lawmakers on Capitol Hill.

“She’s been a great partner of mine and worked really closely with me,” Biden said of Jayapal at an April event in Auburn, Washington.

“One of the things that the president has said to me — and that I really feel — is that we’ve had his back,” Jayapal, told The Associated Press. “We were the loudest and the best champions of the president’s agenda and we really worked hard to make the case to the country for that agenda.”

Despite some glaring exceptions, much of the progressives’ wish list become law, a testament to the willingness of Democratic lawmakers to accept what was politically possible.

“Two years ago, few would have expected that we’d be able to pass the biggest climate bill in history, issue direct checks for millions of Americans, pass the first major gun safety bill in a generation and cancel up to $20,000 of student debt,” said Minnesota Rep. Ilhan Omar, a member of the caucus leadership.

Those efforts weren’t without pain.

Much to their chagrin, progressives had to relent on their initial insistence that a bipartisan infrastructure bill move in tandem with a separate package on social spending that would represent the party’s most ambitious priorities. Then came the spectacular collapse of Biden’s negotiations with Sen. Joe Manchin, D-W.Va., just before Christmas, triggering the precise scenario progressives had long feared.

Tensions seemed to be flaring again last week, when a letter from the caucus signed by 30 lawmakers and urging Biden to engage in direct diplomatic talks with Russia over its invasion of Ukraine generated intense blowback.

As talk swirled that liberal support for arming Ukraine was now in doubt, several of the Democrats on the letter disavowed it, saying it had been signed months ago at a different time in the war. The caucus ultimately retracted the letter, all while insisting that there was no daylight between the group’s position and Biden’s.

Even afterward, senior White House officials were trying to tamp down anger within the party.

Klain, Biden’s top aide, told at least one frustrated House Democrat who wanted to say something publicly about the letter that Democrats needed to direct their energy toward Republicans before the election rather than at each other, according to two officials who were not authorized to publicly discuss private conversations and spoke on condition of anonymity.

But rifts with the left have been the exception, not the rule, during Biden’s term. Progressives, nearly certain to be reelected from deep-blue districts, are making plans for how they can use their platform in the next Congress to again push the party in a progressive direction.

“If Democrats lose some power this election, the White House and the entire party will benefit from very clear distinctions on popular issues like Social Security, and progressives are the ones who innately are more equipped to be full-throated in making the case for these popular economic priorities,” said Adam Green, co-founder of the Progressive Change Campaign Committee and a former adviser to Sen. Elizabeth Warren, the Massachusetts Democrat who ran for president in 2020.

___

Follow the AP’s coverage of the 2022 midterm elections at https://apnews.com/hub/2022-midterm-elections. And learn more about the issues and factors at play in the midterms at https://apnews.com/hub/explaining-the-elections.