Mr McCarthy won by a margin of 216-211.
Congress cannot function without a House Speaker, marking the role as one of the most powerful positions in US politics.
Mr McCarthy was elected with the votes of fewer than half the House members only because five in his own party withheld their votes – not backing either him or another contender.
This week's failed votes marked the highest number of ballots for the speakership since 1859.
Click here to sign up for our newsletters.