WASHINGTON (AP) — Republican Kevin McCarthy was elected House speaker on a historic post-midnight 15th ballot early Saturday, overcoming holdouts from his own ranks and floor tensions that boiled over after a chaotic week that tested the new GOP majority’s ability to govern.

“My father always told me, it’s not how you start, it’s how you finish,” McCarthy told cheering fellow Republicans.

Eager to confront President Joe Biden and the Democrats, he promised subpoenas and investigations. “Now the hard work begins,” the California Republican declared. He credited former President Donald Trump for standing with him and for making late calls “helping get those final votes.”

Republicans roared in celebration when his victory was announced, chanting “USA! USA!”

Finally elected, McCarthy took the oath of office, and the House was finally able to swear in newly elected lawmakers who had been waiting all week for the chamber to formally open and the 2023-24 session to begin.

After four days of grueling ballots, McCarthy flipped more than a dozen conservative holdouts to become supporters, including the chairman of the chamber’s Freedom Caucus.

He fell one vote short on the 14th ballot, and the chamber became raucous, unruly.

McCarthy strode to the back of the chamber to confront Republican Matt Gaetz, sitting with Lauren Boebert and other holdouts. Fingers were pointed, words exchanged and violence apparently just averted.

At one point, Republican Mike Rogers of Alabama, shouting, approached Gaetz before another Republican, Richard Hudson of North Carolina, physically pulled him back.

“Stay civil!” someone shouted.

Order restored, the Republicans fell in line to give McCarthy the post he had fought so hard to gain, House speaker, second in the line of succession to the presidency.

The few remaining Republican holdouts began voting present, dropping the tally he needed. It was the end of a bitter standoff that had shown the strengths and fragility of American democracy.

The tally was 216-212 with Democrats voting for leader Hakeem Jeffries, and six Republican holdouts to McCarthy simply voting present.

The night’s stunning turn of events came after McCarthy agreed to many of the detractors’ demands — including the reinstatement of a longstanding House rule that would allow any single member to call a vote to oust him from office.

Even as McCarthy secured the votes he needs, he will emerge as a weakened speaker, having given away some powers and constantly under the threat of being booted by his detractors.

But he could also be emboldened as a survivor of one of the more brutal fights for the gavel in U.S. history. Not since the Civil War era has a speaker’s vote dragged through so many rounds of voting.

The showdown that has stymied the new Congress came against the backdrop of the second anniversary of the Jan. 6, 2021, attack on the Capitol, which shook the country when a mob of Trump’s supporters tried to stop Congress from certifying the Republican’s 2020 election defeat to Biden.

At a Capitol event Friday, some lawmakers, all but one of them Democrats, observed a moment of silence and praised officers who helped protect Congress on that day. And at the White House, Biden handed out medals to officers and others who fought the attackers.

“America is a land of laws, not chaos,” he said.

At the afternoon speaker’s vote, a number of Republicans tiring of the spectacle temporarily walked out when one of McCarthy’s most ardent challengers, Gaetz, railed against the GOP leader.

Contours of a deal with conservative holdouts who had been blocking McCarthy’s rise had emerged the night before, and took hold after four dismal days and 14 failed votes in an intraparty standoff unseen in modern times.

One significant former holdout — Republican Scott Perry, chairman of the conservative Freedom Caucus, who had been a leader of Trump’s efforts to challenge the 2020 election — tweeted after his switched vote for McCarthy, “We’re at a turning point.”

Trump may have played a role in swaying some holdouts — calling into a meeting of Republican freshmen the night before, and calling other members ahead of voting. He had urged Republicans to wrap up their public dispute.

As Republican Mike Garcia of California nominated McCarthy on an earlier ballot Friday, he also thanked the U.S. Capitol Police, who were given a standing ovation for protecting lawmakers and the legislative seat of democracy on Jan. 6, 2021.

But in nominating the Democratic leader Jeffries, Democrat Jim Clyburn of South Carolina recalled the horror of that day. “The eyes of the country are on us today,” he told his colleagues.

Electing a speaker is normally an easy, joyous task for a party that has just won majority control. But not this time: About 200 Republicans were stymied by 20 far-right colleagues who said McCarthy was not conservative enough. Only the 12th ballot on Friday afternoon did McCarthy start making gains, flipping their votes to support.

The House adjourned Friday until late in the night, giving time for last-minute negotiations and allowing two absent Republican colleagues to return to Washington.

The disorganized start to the new Congress pointed to difficulties ahead with Republicans now in control of the House, much the way that some past Republican speakers, including John Boehner, had trouble leading a rebellious right flank. The result: government shutdowns, standoffs and Boehner’s early retirement when conservatives threatened to oust him.

The agreement McCarthy presented to the holdouts from the Freedom Caucus and others centers around rules changes they have been seeking for months. Those changes would shrink the power of the speaker’s office and give rank-and-file lawmakers more influence in drafting and passing legislation.

At the core of the emerging deal was the reinstatement of a House rule that would allow a single lawmaker to make a motion to “vacate the chair,” essentially calling a vote to oust the speaker. McCarthy had resisted allowing a return to the longstanding rule that former Speaker Nancy Pelosi had done away with, because it had been held over the head of Boehner. But it appears McCarthy had no other choice.

Other wins for the holdouts are more obscure and include provisions in the proposed deal to expand the number of seats available on the House Rules Committee; to mandate 72 hours for bills to be posted before votes; and to promise to try for a constitutional amendment that would impose federal limits on the number of terms a person could serve in the House and Senate.

___

Associated Press writers Mary Clare Jalonick and Kevin Freking and video journalists Nathan Ellgren and Mike Pesoli contributed to this report.