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

John Fetterman’s success in flipping Pennsylvania’s Republican-controlled Senate seat lifted Democratic hopes of maintaining control of the chamber. Republicans found a bright spot in Wisconsin, where Sen. Ron Johnson’s victory raised the stakes of races where results were unclear and vote counting continued.

In the House, Democrats kept seats in districts from Virginia to Kansas to Rhode Island, while many in states like New York and California had not been called. But Republicans notched several important victories in their bid to flip the five 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.

The race for control of Congress will determine 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.

House Minority Leader Kevin McCarthy of Calif., arrives to speak at an event early Wednesday morning, Nov. 9, 2022, in Washington. (AP Photo/Alex Brandon)

Democrats. though, 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 WisconsinMichigan and Pennsylvania — battlegrounds critical to Biden’s 2020 win over Donald Trump. But Republicans held on to governors’ mansions in FloridaTexas and Georgia, another battleground state Biden narrowly won two years ago.

Though neither party had yet secured a majority in either congressional chamber, the midterms didn’t feature a strong GOP surge, uplifting for Democrats who had braced for sweeping losses — and raising 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 battleground, Pennsylvania Democrats won the governorship to go along with their Senate victory. Fetterman had faced questions about his fitness for office after suffering a stroke but topped 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.

“I’m so humbled,” Fetterman, wearing his signature hoodie, told supporters. “This campaign has always been about fighting for everyone who’s ever been knocked down that ever got back up.”

Democrats also held a crucial Senate seat in New Hampshire, where incumbent Maggie Hassan defeated Republican Don Bolduc, a retired Army general who had initially promoted Trump’s lies about the 2020 election being marred by widespread fraud that did not occur but tried to shift away from some of the more extreme positions he took during the GOP primary.

Democrats Tony Evers in Wisconsin, Gretchen Whitmer of Michigan, Kathy Hochul of New York, Michelle Lujan Grisham of New Mexico and Janet Mills of Maine also repelled Republican challengers.

Incumbent Republican governors had some success. Georgia Gov. Brian Kemp won reelection, defeating Stacey Abrams in a rematch of their 2018 race. Florida Gov. Ron DeSantis and Texas Gov. Greg Abbott, two future possible Republican presidential contenders, beat back Democratic challengers to win in the nation’s two largest red states.

Democratic Gov. Laura Kelly won reelection in conservative Kansas, despite a GOP push to flip it. In liberal Oregon, Democrat Tina Kotek was fighting for victory in a three-way governor’s race.

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.

Democratic Reps. Abigail Spanberger and Jennifer Wexton held off spirited Republican challengers in Virginia districts the GOP had hoped to flip.

The 2022 elections are on track to cost a projected $16.7 billion at the state and federal level, making them the most expensive midterms ever, according to the nonpartisan campaign finance tracking organization OpenSecrets.

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.