WASHINGTON (AP) — Republicans were closing in Wednesday on a narrow House majority while control of the Senate hinged on a series of tight races in a midterm election that defied expectations of sweeping conservative victories driven by frustration over inflation and President Joe Biden’s leadership.

Either party could secure a Senate majority with wins in both Nevada and Arizona — where the races were too early to call. But there was a strong possibility that, for the second time in two years, the Senate majority could come down to a runoff in Georgia next month, with Democratic Sen. Raphael Warnock and Herschel Walker failing to earn enough votes to win outright.

In the House, Democrats kept seats in districts from Virginia to Pennsylvania to Kansas, while many in states like New York and California had not been called. But Republicans notched several important victories in their bid to get to the 218 seats needed to reclaim the House majority. In a particularly symbolic victory, the GOP toppled House Democratic campaign chief Sean Patrick Maloney of New York.

Control of Congress will be a key factor in determining the future of Biden’s agenda and serve as a referendum on his administration as the nation reels from record-high inflation and concerns over the direction of the country. A Republican House majority would likely trigger a spate of investigations into Biden and his family, while a GOP Senate takeover would hobble the president’s ability to make judicial appointments.

“Regardless of what the final tally of these elections show, and there’s still some counting going on, I’m prepared to work with my Republican colleagues,” Biden said Wednesday, in his first public remarks since the polls closed. “The American people have made clear, I think, that they expect Republicans to be prepared to work with me as well.”

Democrats saw candidates who prioritized protecting abortion rights after this summer’s Supreme Court decision overturning the landmark Roe v. Wade court decision, perform well. The party won governors’ races, winning in Wisconsin, Michigan and Pennsylvania — battlegrounds critical to Biden’s 2020 win over Donald Trump. But Republicans held on to governors’ mansions in Florida, Texas and Georgia, another battleground state Biden narrowly won two years ago.

Even if the GOP ultimately wins the House, it won’t be by a margin as large as during other midterm cycles. Democrats gained a net of 41 House seats under Trump in 2018, President Barack Obama saw the GOP gain 63 gain in 2010 and Republicans gained 54 seats in 1994, during the Bill Clinton administration.

A small majority in the House would pose a great challenge for the GOP and especially California Rep. Kevin McCarthy, who is in line to be House speaker and would have little room for error in navigating a chamber of members eager to leverage their votes to advance their own agenda.

Though neither party had yet secured a majority in either congressional chamber, the midterms — on track to be the most expensive ever — didn’t feature a strong GOP surge, uplifting for Democrats who had braced for sweeping losses. That raised questions about how big the Republicans could hope their possible majority might be.

“As we sit here I can’t, with 100% certainty, tell you who holds the House majority,” said Maloney whose defeat marks the first time since 1980 the head of the Democratic House campaign arm has been defeated. “If we fall a little short, we’re going to know that we gave it our all and we beat the spread.”

Democrats had faced historic headwinds. The party in power almost always suffers losses in the president’s first midterm elections, but Democrats bet that anger from the Supreme Court’s decision to gut abortion rights might energize their voters to buck historical trends.

In Pennsylvania, Democrats won the governorship and Senate in the key battleground state. Lt. Gov. John Fetterman, who suffered a stroke five months ago, flipped a Republican-controlled Senate seat, topping Trump-endorsed Republican Dr. Mehmet Oz. In the governor’s race Democratic Attorney General Josh Shapiro beat Republican Doug Mastriano, an election denier who some feared would not certify a Democratic presidential win in the state in 2024.

Georgia, meanwhile, was set for yet another runoff on Dec. 6. In 2021, Warnock used a runoff to win his seat as did Democratic Sen. Jon Ossoff — which gave Democrats control of the Senate. Both Warnock and Walker were already fundraising off the race stretching into a second round.

Both Republicans and Democratic incumbents maintained key Senate seats. In Wisconsin, Republican Sen. Ron Johnson prevailed over Democratic Lt. Gov. Mandela Barnes, while in New Hampshire, Democratic Sen. Maggie Hassen beat Don Bolduc, a retired Army general who had initially promoted Trump’s lies about the 2020 election but tried to shift away those views closer to Election Day.

AP VoteCast, a broad survey of the national electorate, showed that high inflation and concerns about the fragility of democracy were heavily influencing voters. Half of voters said inflation factored significantly, with groceries, gasoline, housing, food and other costs that have shot up in the past year. Slightly fewer — 44% — said the future of democracy was their primary consideration.

Biden didn’t entirely shoulder the blame for inflation, with close to half of voters saying the higher-than-usual prices were more because of factors outside of his control. And despite the president bearing criticism from a pessimistic electorate, some of those voters backed Democratic candidates.

Biden spent the night calling Democrats to congratulate them on their wins and was holding a late Wednesday afternoon news conference at the White House.

Democrats were betting on a midterm boost resulting from voter outrage over the elimination of a woman’s constitutional right to an abortion. Voters in reliably red Kentucky rejected a ballot measure aimed at denying any constitutional protections for abortion. Voters in the swing state of Michigan voted to amend their state’s constitution to protect abortion rights.

The result mirrored what happened in another red state, Kansas, where voters in August rejected changing that state’s constitution to let lawmakers tighten restrictions or ban abortions. Voters in the swing state of Michigan, meanwhile, voted to amend their state’s constitution to protect abortion rights.

VoteCast showed that 7 in 10 national voters said overturning the 1973 Roe v. Wade decision was an important factor in their midterm decisions. It also showed the reversal was broadly unpopular. And roughly 6 in 10 say they favor a law guaranteeing access to legal abortion nationwide.

There were no widespread problems with ballots or voter intimidation reported around the country, though there were hiccups typical of most Election Days.

In the first national election since the Jan. 6 insurrection, some who participated in or were in the vicinity of the attack on the U.S. Capitol were poised to win elected office. One of those Republican candidates, Derrick Van Orden in Wisconsin — who was outside the Capitol during the deadly riot — won a House seat. Another, J.R. Majewski lost to Ohio Democratic Rep. Marcy Kaptur.

Trump lifted Republican Senate candidates to victory in Ohio and North Carolina. JD Vance, the bestselling author of “Hillbilly Elegy,” defeated 10-term congressman Tim Ryan, while Rep. Ted Budd beat Cheri Beasley, the former chief justice of the state Supreme Court.

Trump had endorsed more than 300 candidates across the country, hoping the night would end in a red wave he could ride to the 2024 Republican presidential nomination. After summoning reporters and his most loyal supporters to a watch party at his Mar-a-Lago club in Florida on Tuesday, he ended the night without a triumphant speech.

Still, the former president insisted on social media that he’d had “A GREAT EVENING.” Hours later, Palm Beach County issued an evacuation order for an area that included Trump’s club with Tropical Storm Nicole approaching.

___

Associated Press writer Hannah Fingerhut contributed.