LOS ANGELES (AP) — Two months after his historic ouster as U.S. House speaker, Republican Rep. Kevin McCarthy said Wednesday that he is resigning and will leave Congress by the end of the year.

His announcement capped a stunning end to a House career for the onetime deli counter owner from Bakersfield, California, who ascended through state and national politics to become second in line to the presidency, until a cluster of hard-right conservatives engineered his removal in October.

McCarthy is the only speaker in history to be voted out of the job.

“No matter the odds, or personal cost, we did the right thing,” McCarthy wrote in The Wall Street Journal, announcing his decision. “It is in this spirit that I have decided to depart the House at the end of this year to serve America in new ways.”

Word about McCarthy’s future had been expected, days before the filing deadline to seek reelection to the House. But his decision ricocheted across Capitol Hill, where his departure will leave the already paper-thin House GOP majority even tighter, with just a few seats to spare.

It adds to a wave of retirements in both parties, as many members seek higher office or look to escape the partisan rancor that often paralyzes the chamber. Republicans have been split by infighting and the rare expulsion last week of indicted GOP Rep. George Santos of New York, dashing hopes for major accomplishments and leaving the majority straining to conduct the basic business of governing.

It’s also the end of an era for a generation of House Republicans led by McCarthy and former Reps. Paul Ryan and Eric Cantor, the so-called “Young Guns” whose book of the same title outlined a new style of GOP governance. Ryan and Cantor are gone, and McCarthy will soon exit.

McCarthy had brought the Republicans into the majority but found it was much more difficult to lead the GOP’s factions.

His toppling from the speaker’s post was fueled by grievances from his party’s hard-right flank, including over his decision to work with Democrats to keep the federal government open rather than risk a shutdown.

House Speaker Mike Johnson of Louisiana, a Republican who succeeded McCarthy as speaker, tweeted that McCarthy “served faithfully and sacrificed substantially for the good of our country and our cause.”

Speaking later with reporters, Johnson called McCarthy a “long and trusted friend” and said he was “sad to see him go.”

Rep. Matt Gaetz, R-Fla., who led the effort to remove McCarthy, tweeted a one-word response after his announcement: “McLeavin.”

He later chastised McCarthy, whose departure will further narrow the GOP’s fragile hold on power. “I think he should have stuck around and helped us hold a strong majority,” Gaetz told reporters. “But he left.”

McCarthy, 58, arrived in the House in January 2007 after a stint in the California Assembly, where he was minority leader. In Congress, he maneuvered through his party’s hierarchy before being elected speaker in January.

The dayslong floor fight that preceded his elevation to the House’s top job foreshadowed a stormy tenure, at a time when former President Donald Trump remained the de facto leader of the party and deep divisions within the GOP raised serious questions about the party’s ability to govern.

It took a record 15 votes over four days for McCarthy to line up the support he needed to win the post he had long coveted, finally prevailing on a 216-212 vote with Democrats backing leader Hakeem Jeffries of New York and six Republican holdouts voting present. Not since the Civil War era has a speaker’s vote dragged through so many rounds of counting.

McCarthy emerged from the fight weakened, especially considering Republicans held only a fragile margin in the chamber after a predicted “red wave” failed to materialize in the 2022 elections.

In the speaker’s job, McCarthy’s well-known savvy for fundraising and political glad-handing appeared ill-suited for corralling his party’s hard-right members. Deals he cut to become speaker — including a rules change that allowed any single lawmaker to file a motion to remove him — left him vulnerable.

When he became speaker, “he faced new challenges that required a different skill set,” said Claremont McKenna College political scientist Jack Pitney, a onetime domestic policy analyst for House Republicans. And “the deals he made to become speaker made it almost impossible for him to succeed as speaker.”

McCarthy, the son of a firefighter and a homemaker, has long depicted himself as a tireless battler. He is fond of quoting his father, who told him, “It’s not how you start, it’s how you finish.”

McCarthy is from a Republican-leaning area in Central California where oil derricks blanket hillsides and country music fans pack into Buck Owens’ Crystal Palace hall. Far from the Southern California beaches and San Francisco’s restaurants, farming and oil pumping shape the economy.

It wasn’t immediately clear what would happen with the vacancy, which could have implications for Republican control. Only a handful of seats separates the two parties.

In California, Friday is the last day for candidates to file paperwork to enter the 2024 elections. If the vacancy occurs before the end of that period, Democratic Gov. Gavin Newsom would be required to call a special election to fill McCarthy’s seat.

If McCarthy steps down after that time, it would be up to the governor to decide whether to call a special election.

McCarthy has been credited with helping recruit a new, more diverse generation of GOP House members, including in his home state, where the delegation includes two South Korean immigrants, both women.

Rep. Carlos Gimenez, R-Fla., was handpicked by McCarthy in 2020 to run for a House seat that had swung back and forth between Democrats and Republicans for several elections. McCarthy’s instinct turned out to be right and Gimenez won that election over an incumbent Democrat.

“I surely will miss him, but I think the House will miss him more,” Gimenez said.

He said McCarthy’s departure could put House Republicans at a financial disadvantage in their efforts to keep the majority.

McCarthy exited with a reminder of his fundraising prowess. Just before Thanksgiving, he transferred $3 million of his political funds to vulnerable GOP members, state Republican parties and the House GOP campaign arm, spokesperson Drew Florio said in an email.

“Nobody could raise funds like Kevin McCarthy could,” Gimenez said. “To replace him at this point, at this short time for the next election, that’s an impossible task for Speaker Johnson. If he comes even close, I will take my hat off to him.”

___

Freking reported from Washington. AP Congressional Correspondent Lisa Mascaro in Washington contributed to this report.