McCarthy was always the frontrunner to lead the Republican-led House, but his victory in the small hours of the morning was almost derailed by a right-wing revolt in his party that extended the contest to a historic 15 rounds of voting.
The speaker wields huge influence in Washington by presiding over House business and is second in line to the presidency, after the vice president.
As he accepted the gavel, McCarthy vowed House Republicans would "pass bills to fix the nation's challenges, from the wide open southern border to 'America last' energy policies, to woke indoctrination in our schools."
"America's long term challenges -- the debt and the rise of the Chinese Communist Party -- Congress must be with one voice on both of these issues," he told the House.
Democratic US President Joe Biden congratulated McCarthy in a statement calling for cooperation between the leaders of the two parties.
"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," Biden said.
McCarthy had been hoping to secure the gavel in the 14th voting round before midnight Friday but suffered a shock setback amid astonishing scenes of Republican infighting as he came up short of a majority by just one vote out of more than 400 cast.
As Matt Gaetz voted "present" to deny McCarthy the gavel, the disappointed Republican leader went over to talk to the Florida lawmaker-elect face-to-face.
Gaetz pointed a finger at McCarthy, who began retreating as Alabama's Mike Rogers lunged at Gaetz and had to be held back with a restraining arm across his face.
"The 'Speaker' selection process, as crazy as it may seem, has made it all much bigger and more important than if done the more conventional way," former president Donald Trump chimed in on his Truth Social platform.
"Congratulations to Kevin McCarthy and our GREAT Republican Party!"
The Republicans, who hold a razor-thin majority, had been mired in internecine warfare as Trump-backed McCarthy failed to win the speakership in multiple ballots, with around 20 conservative hardliners blocking his path since Tuesday.
But the 57-year-old Californian was able to pick up more than a dozen votes among the defectors in two afternoon voting rounds Friday after offering major concessions.
McCarthy predicted he would win in the 14th round -- but suffered a humiliation given wall-to-wall coverage on US news channels before finally bagging his victory in the 15th.