Republican Majority Leader Kevin McCarthy was elected Speaker of the US House of Representatives early on Saturday after falling short in 14 previous rounds of voting.
Mr McCarthy had been stymied by a group of about 20 Republicans holding personal or ideological grievances against him.
Despite him offering a string of concessions, the rebels did not budge in their opposition during 11 votes earlier this week.
Mr McCarthy was declared elected with 216 out of 428 votes, triggering chants of "USA" in the House.
"I hope one thing is clear after this week: I will never give up," he said in a tweet after his election.
In the first two rounds of voting on Friday, the fourth day of proceedings, Mr McCarthy flipped 15 conservative holdouts to become supporters, leaving him just a few shy of seizing the gavel for the new Congress.
He drew even closer in the 14th round on Friday night, receiving 216 out of 432 votes — just one vote short.
The increased support for Mr McCarthy in the earlier votes on Friday came after he told reporters that he had seen some encouraging signs.
“We've got some progress going on. We've got members talking. I think we've got a little movement, so we'll see,” he said.
Mr McCarthy needed to secure 218 votes to be elected speaker if all 434 members of the House are present. With Republicans holding a slim majority of 222 seats after the US midterms, he could afford to lose only four votes.
The Republican holdouts have made the speaker's election the most drawn-out process of its kind since before the US Civil War.
This week's 15 votes marked the highest number of ballots for the speakership since 1859.
“Now, the hard work begins,” Mr McCarthy said in his first address to the House as speaker. He ran through the broad strokes of his agenda, including strengthening the southern US border, addressing federal debt, confronting the rise of China and investigating the Biden administration. “We will use the power of the purse, and the power of the subpoena, to get the job done,” he said.
President Joe Biden, who had earlier described the drawn-out election of a speaker as "not a good look", said it was now time to "govern responsibly and to ensure that we're putting the interests of American families first".
“As I said after the midterms, I am prepared to work with Republicans when I can, and voters made clear that they expect Republicans to be prepared to work with me as well," Mr Biden said.
"Now that the leadership of the House of Representatives has been decided, it is time for that process to begin.”
Without a speaker, the chamber was unable to swear in members and begin its 2023-24 session.
The election saga and scenes of chaos in the House have raised questions about whether America is vulnerable from a national security standpoint, as without the chamber, wars cannot be started or ended.
John Kirby, spokesman for the National Security Council, was asked at a press conference about the potential impacts of not having a functioning House.
There is “no particular worry or concern that national security will be put at significant risk here”, he said.
“I don't want to suggest that there's not going to be any national security impacts … but [it] should not be an overriding concern.”
The speaker's gavel gives Mr McCarthy the authority to block Mr Biden's legislative agenda, force votes for Republican priorities on the economy, energy and immigration, and move forward with investigations into the President, his family and his administration.
But the holdouts wanted a deal that would make it easier to oust the speaker and give them greater influence within the House Republican caucus and on congressional committees.
Late on Wednesday, some Republicans expressed hope for a deal, but some of Mr McCarthy's “never Kevin” opponents showed no sign of yielding.
“This ends in one of two ways: either Kevin McCarthy withdraws from the race or we construct a straitjacket that he is unwilling to evade,” said Republican Matt Gaetz, who on Thursday voted for Donald Trump to be speaker.
A speaker does not necessarily need to be a member of Congress.
Ellie Sennett contributed to this report from the White House