Republican Kevin McCarthy flipped more than a dozen colleagues to support him in dramatic votes Friday for House speaker, nearing victory on the fourth day and 12th ballot of a grueling standoff that was testing American democracy.

The changed votes from conservative holdouts, including the chairman of the chamber’s Freedom Caucus, put McCarthy close to seizing the gavel. It was the first time he had won the most votes, 213, though he still fell short of a majority.

A 13th vote was swiftly launched, this time, just between McCarthy and the Democratic leader, without a Republican challenger to siphon GOP votes away.

The stunning turnaround 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. That change and others mean the job he fought so hard to gain will be somewhat weakened.

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 then-President Donald Trump’s supporters tried to stop Congress from certifying the Republican’s 2020 election defeat to Democrat Joe Biden.

A few minutes before voting began in the House chamber, Republicans tiring of the spectacle walked out when one of McCarthy’s most ardent challengers railed against the GOP leader.

“We do not trust Mr. McCarthy with power,” said Republican Matt Gaetz of Florida, as colleagues streamed out of the chamber in protest of his remarks.

Contours of a deal with conservative holdouts who have been blocking McCarthy’s rise emerged, but agreement had seemed still out of reach after three dismal days and 11 failed votes in a political spectacle unseen in a century.

But an upbeat McCarthy told reporters as he arrived at the Capitol Friday morning, “We’re going to make progress. We’re going to shock you.”

One significant former holdout, Republican Scott Perry, chairman of the conservative Freedom Caucus, tweeted after his switched vote for McCarthy: “We’re at a turning point.”

But several holdouts remained. The final 12th vote tally: McCarthy, 213 votes; Democrat Hakeem Jeffries 211. Other Republcans Jim Jordan and Kevin Hern picked up protest votes. With 431 people voting, due to absences, McCarthy was a few votes short of the majority.

When Rep. Mike Garcia nominated McCarthy for a 12th time, 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.

The chamber is unable swear in members and begin its 2023-24 session. McCarthy told lawmakers there were no plans to adjourn for the weekend, one Republican said, but it might be difficult to keep them in town.

So far Republicans have been unable to settle on a new speaker — normally an easy, joyous task for a party that has just won majority control. But not this time: About 200 Republicans have been stymied by 20 far-right colleagues who said he’s not conservative enough.

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.

Even if McCarthy is able to secure the votes he needs, he will emerge as a weakened speaker, having given away some powers, leaving him constantly under threat of being voted out by his detractors. But he would also be potentially emboldened as a survivor of one of the more brutal fights for the gavel in U.S. history.

At the core of the emerging deal is 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 past Republican Speaker John Boehner, chasing him to early retirement. But it appears he had no other choice.

The chairman of the chamber’s Freedom Caucus, Scott Perry of Pennsylvania, who had been a leader in Trump’s efforts to challenge his presidential election loss to Democrat Joe Biden, appeared receptive to the proposed package, tweeting an adage from Ronald Reagan, “Trust but verify.”

Other wins for the holdouts 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.

Lest hopes get ahead of reality, conservative holdout Ralph Norman of South Carolina said: “This is round one.”

It could be the makings of a deal to end a standoff that has left the House unable to fully function. Members have not been sworn in and almost no other business can happen. A memo sent out by the House’s chief administrative officer Thursday evening said that committees “shall only carry-out core Constitutional responsibilities.” Payroll cannot be processed if the House isn’t functioning by Jan. 13.

After a long week of failed votes, Thursday’s tally was dismal: McCarthy lost seventh, eighth and then historic ninth, 10th and 11th rounds of voting, surpassing the number from 100 years ago in the last drawn-out fight to choose a speaker.

The California Republican exited the chamber and quipped about the moment: “Apparently, I like to make history.”

Feelings of boredom, desperation and annoyance seemed increasingly evident.

Democrats said it was time to get serious. “This sacred House of Representatives needs a leader,” said Democrat Joe Neguse of Colorado, nominating his own party’s leader, Hakeem Jeffries, as speaker.

What started as a political novelty, the first time since 1923 a nominee had not won the gavel on the first vote, has devolved into a bitter Republican Party feud and deepening potential crisis.

Democratic leader Jeffries of New York won the most votes on every ballot but also remained short of a majority. McCarthy ran second, gaining no ground.

Pressure has grown with each passing day for McCarthy to somehow find the votes he needs or step aside. The incoming Republican chairmen of the House’s Foreign Affairs, Armed Services and Intelligence committees all said national security was at risk.

Republican Party holdouts repeatedly put forward the name of Rep. Byron Donalds of Florida, ensuring continuation of the stalemate that increasingly carried undercurrents of race and politics. They also put forward Republican Kevin Hern of Oklahoma, splitting the protest vote.

Donalds, who is Black, is seen as an emerging party leader and a GOP counterpoint to the Democratic leader, Jeffries, who is the first Black leader of a major political party in the U.S. Congress and on track himself to become speaker some day.

Ballots kept producing almost the same outcome with 20 conservative holdouts still refusing to support McCarthy, leaving him far short of the 218 typically needed to win the gavel.

In fact, McCarthy saw his support slip to 201, as one fellow Republican switched to vote simply “present,” and later to 200. With just a 222-seat GOP majority, he could not spare votes.

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 Boehner, had trouble leading a rebellious right flank. The result: government shutdowns, standoffs and Boehner’s early retirement.

The longest fight for the gavel started in late 1855 and dragged on for two months, with 133 ballots, during debates over slavery in the run-up to the Civil War.