Kevin McCarthy. (Getty/Kyodo)

Republican Kevin McCarthy was elected U.S. House of Representatives speaker on the 15th round of voting early Saturday, following days of deadlock amid resistance from several of his party's far-right members close to former President Donald Trump.

The latest contest for the speakership became the longest in 164 years, according to U.S. media.

The ballot took place as the new U.S. Congress session opened Tuesday, with Republicans securing a slim majority in the House in the U.S. midterm elections in November. The Democratic Party, led by President Joe Biden, retains control of the Senate.

Biden congratulated the 57-year-old California congressman on his election as speaker, reiterating that he is "prepared to work" with Republicans when he can as his administration seeks to defend the country's national security and grow the economy.