Republicans secured the majority in the U.S. House of Representatives on Wednesday, boosting the party’s ability to stymie President Biden’s agenda even though the midterm results stop well short of a mandate from the electorate.

It took more than a week for the Associated Press to determine the GOP had won the 218 seats needed to win control. The belated milestone underscored Republicans’ underwhelming performance in an election cycle when economic conditions, historical precedent and a sour national mood had been expected to give them a greater advantage.

The party’s gains mean Biden will contend with a divided government in the latter half of his current term. Democrats have cemented control of the Senate with 50 seats, and can further bolster their ranks if Sen. Raphael Warnock wins reelection in a Georgia runoff next month.

Republicans had projected confidence before last week’s election of a “red wave” that would yield them at least a dozen more House seats. But Democrats’ surprising strength, powered largelyby voter outrage over the Supreme Court’s reversal of federal abortion protections, blunted the GOP’s edge to single digits.

Republicans claimed their majority with a victory by Rep. Mike Garcia over Democrat Christy Smith in a northern Los Angeles County district that Biden won by 12 points in 2020. The AP called the race Wednesday, though official results will take longer. Six competitive races, including four California contests, remain to be called.

“Republicans have officially flipped the People’s House! Americans are ready for a new direction, and House Republicans are ready to deliver,” House GOP leader Kevin Mc-Carthy tweeted after his party clinched control of the chamber.

Biden congratulated McCarthy and pledged a willingness to collaborate with the GOP, reiterating his call to move past “political warfare.”

“The American people want us to get things done for them,” he said. “They want us to focus on the issues that matter to them and on making their lives better. And I will work with anyone — Republican or Democrat — willing to work with me to deliver results.”

A Republican House is widely expected to clash with the Democratic president on policy, including potential standoffs over raising the debt limit and providing more aid to Ukraine. GOP members have also threatened impeachment proceedings against Biden and members of his Cabinet, and have vowed to launch multiple investigations, particularly into allegations against Hunter Biden, the president’s son.

But the GOP confer-ence’s relatively small majority could exacerbate its ideological fissures. Many of the incoming members from deep-red districts hail from the party’s right flank and are loyal to former President Trump, even as prominent Republicans grow increasingly vocal about his drag on the GOP. A narrow majority means that a small number of defectors can have an outsized impact on the party’s agenda.

McCarthy, who has doggedly pursued the speakership, has played down disappointment that Republicans didn’t pick up a larger number of seats.

“Remember, in the House, they don’t give gavels out by ‘small,’ ‘medium’ and ‘large.’ They just give you the gavel,” he told Fox News’ Jesse Watters, referring to the symbol of House control. “And we’re going to be able to govern.”

But his party’s slim margin leaves the Bakersfield Republican little room for error as he seeks the votes to become the next speaker. Though McCarthy had assiduously worked to strengthen alliances with the GOP’s most conservative faction, he nevertheless faced open hostilities from the right after he led the party to a lackluster midterm showing.

Republican Rep. Matt Gaetz of Florida, a staunch Trump ally, blasted McCarthy last week, tweeting that he represented “FLIGHT over FIGHT when the chips are down” and “is not a Speaker for these times.”

McCarthy cleared the first hurdle for the job on Tuesday after House Republicans voted for him to be nominated speaker. But with roughly 30 conservatives backing a challenge by Rep. Andy Biggs of Arizona, it is clear McCarthy does not yet have the 218 votes necessary to cement his place as top House leader.

“My bid to run for speaker is about changing the paradigm and the status quo,” Biggs tweeted before the vote. “Minority Leader McCarthy does not have the votes needed to become the next speaker of the House and his speakership should not be a foregone conclusion.”

The speaker of the next Congress will officially be determined by a vote of the entire House in January.

The current speaker — Nancy Pelosi of San Francisco — agreed in 2018 to step down from House Democratic leadership by the end of 2022. Her spokesman said she would announce her plans Thursday.

“House Democrats defied expectations with an excellent performance: running their races with courage, optimism and determination,” Pelosi said Wednesday. “In the next Congress, [they] will continue to play a leading role in supporting President Biden’s agenda — with strong leverage over a scant Republican majority.”

Republicans had reason for high hopes this election cycle. Large majorities of voters believe the country is headed in the wrong direction, polls have shown, an indicator that theoretically should bode well for the party that does not hold the White House. Persistent inflation gave them an opportunity to run on the economy — an area where many people tend to favor the GOP over Democrats.

Biden threatened to be an albatross for Democrats. Only twice in the decades after World War II has the party that controlled the White House gained seats in Congress — in 1998 and 2002, when the approval ratings for Presidents Clinton and George W. Bush, respectively, were in the 60s. Biden’s ratings, in contrast, have been in the low 40s.

That Democrats performed so well — not picking up House seats, but avoiding significant losses — makes this midterm even more of an anomaly, said Jacob Rubashkin, an analyst with Inside Elections, a nonpartisan newsletter.

“For the first time, it really does feel like midterm voters were willing to get beyond their dissatisfaction with the president,” he said.

The GOP’s underperformance was most apparent in its failure “to make inroads into places that they were hoping would be most competitive. ... They were unable to claw back the suburbs. And they were unable to make New England Republicans a reality again. And they were unable to dislodge quite a few strong Democratic incumbents in places that they had hoped they could.”

Trump, launching his 2024 presidential bid this week, cheered Republicans’ House takeover, but acknowledged they should have done better.

While a notable number of GOP politicians and media outlets have blamed Trump for boosting candidates with little appeal to voters beyond his base, he had another explanation for the results.

“The citizens of our country have not yet realized the full extent and gravity of the pain our nation is going through,” he said. “They don’t quite feel it yet, but they will very soon.” He predicted the nation will be in worse shape in 2024, leading to a different outcome at the ballot box.

While many analysts acknowledged they were caught off guard by the midterm results, Democratic strategist Simon Rosenberg said there was evidence this spring that his party would overperform.

A confluence of events — the leaked Supreme Court decision on the end of Roe vs. Wade; the mass shooting at an elementary school in Uvalde, Texas; the hearings by the House panel investigating the Jan. 6, 2021, attack on the U.S. Capitol — dovetailed in Democrats’ favor, Rosenberg said.

“Over May and June, the fear of MAGA ... started pressing down on the Republican brand. There was evidence of that in public polling.... And then it became manifest in actual elections, including in red states like Alaska, Kansas and Nebraska,” as well as in voter registration, fundraising, early voting and the general election, he said.

A key driver of Democrats’ success was the issue of abortion, said Rosenberg, who predicted it would cause problems for Republicans for years to come.

The Dobbs vs. Jackson Women’s Health decision “didn’t just change this election,” he said. “It fundamentally changed our politics — there’s a before and after. And the after is really bad for Republicans.”

The conservative-leaning court influenced the election in other ways: Its 2019 decision allowing partisan redistricting enabled both major parties to try to maximize their advantage after the 2020 census.

Republicans benefited most from that ruling, as states including Florida and Georgia produced heavily gerrymandered maps favoring the GOP. Some Democratic efforts to draw their own favorable districts faltered when courts blocked maps in Maryland and New York. The New York ruling was especially consequential for Democrats, who lost five competitive seats in the midterm, including that of Rep. Sean Patrick Maloney, the party’s House campaign committee chair.

The Supreme Court also blocked the redrawing of maps that lower courts said violated the Voting Rights Act. In Alabama and Louisiana, that stopped the creation of additional majority-Black districts likely to favor Democrats.

“The Supreme Court was the hidden player in this election,” said Michael Li, a redistricting expert at the Brennan Center for Justice at NYU Law. “On one hand, the Supreme Court created dynamics pushing the electorate toward Democrats. At the same time, the Supreme Court enabled discriminatory maps that were going to block some of that momentum.”

Redistricting will drag on past this midterm. States including Ohio and North Carolina need to produce new maps. And justices are considering changes to the Voting Rights Act that could allow for the dismantling of minority districts.

“There’s a lot more redistricting and a lot more fighting over maps before the 2024 election is yet to be had,” Li said. “These maps ended up being pretty good for Democrats, all things considered, in a year that should’ve been tough. But these aren’t necessarily the maps we will be using in 2024. Those could be much more favorable toward Republicans.”

Times staff writers Nolan D. McCaskill and Hannah Fry contributed to this report.