Republican Kevin McCarthy was elected US House speaker in a historic post-midnight 15th ballot early on Saturday, overcoming holdouts from his own ranks.
It was the end to a chaotic week that tested the new GOP majority's ability to govern.
After four days of gruelling ballots, Mr McCarthy flipped more than a dozen conservative holdouts to become supporters, including the chairman of the chamber's Freedom Caucus, leaving him just a few shy of seizing the gavel for the new Congress.
As the House resumed for the late night session Mr McCarthy had been on the cusp of victory in the 14th round but he fell one vote short.
He strode to the back of the chamber to confront Matt Gaetz, sitting with Lauren Boebert and other holdouts. Fingers were pointed and words exchanged as the tension came close to erupting in the chamber.
At one point, Republican Mike Rogers of Alabama started to charge toward Mr Gaetz before another Republican, Richard Hudson, physically pulled him back.
"Stay civil!" someone shouted.
Republicans quickly moved to adjourn, but then Mr McCarthy rushed forward to switch his vote to remain in session as colleagues chanted "One more time!"
The few Republican holdouts began voting present as well, dropping the tally he needed to finally seize the gavel in what was heading toward a dramatic finish on the fourth long day of a gruelling standoff that has shown the strengths and fragility of American democracy.
Mr McCarthy had declared to reporters earlier in the day that he believed "we'll have the votes to finish this once and for all".
The day's stunning turn of events came after Mr 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 if Mr McCarthy is able to secure 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 US 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 January 6 2021 attack on the Capitol.
At a Capitol event on Friday, some politicians, mostly Democrats, observed a moment of silence and praised officers who helped protect Congress on that day. And at the White House, Mr 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 Mr McCarthy's most ardent challengers railed against the GOP leader.
Contours of a deal with conservative holdouts who have been blocking Mr McCarthy's rise emerged after three dismal days and 11 failed votes in an intraparty standoff unseen in modern times.
And an upbeat Mr McCarthy told reporters as he arrived at the Capitol, "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 who had been a leader of Mr Trump's efforts to challenge the 2020 election, tweeted after his switched vote for Mr McCarthy: "We're at a turning point."
Another Republican holdout, Byron Donalds of Florida, who was repeatedly nominated as an alternative candidate for speaker, switched on Friday, too, voting for Mr McCarthy.
Mr Trump may have played a role in swaying the holdouts. Mr Donalds said he had spoken to the former president who had been urging Republicans to wrap up their public dispute the day before.