WASHINGTON — Confronting insurmountable obstacles, Majority Leader Kevin McCarthy suddenly withdrew from the contest for speaker of the U.S. House on Thursday, shocking colleagues just before they were to vote and producing ever-deeper chaos for a divided Congress.

"We need a new face," McCarthy declared after a closed-door meeting where House Republicans were prepared to nominate him as speaker but instead listened in disbelief as he took himself out of the running. "If we are going to be strong, we've got to be 100 percent united."

Allies said that even though he would certainly have emerged the winner from Thursday's secret-ballot election of Republicans, McCarthy had concluded he did not have a path to getting the needed 218-vote majority in the full House later this month. A small but determined bloc of conservatives had announced they were opposing him, and they commanded enough votes to block him on the floor.

In an interview published Thursday night by The Wall Street Journal, McCarthy said: "It was only going to get worse. ... This was for the good of the team."

These same lawmakers, members of the hardline House Freedom Caucus, pushed outgoing Speaker John Boehner to announce his resignation just two weeks ago by threatening a floor vote on his speakership. Some of them cheered the announcement by Boehner's No. 2.

"The establishment has lost two speakers in two weeks. K Street must be shaking in their boots. Mitch McConnell must be shaking in his boots, too," said Rep. Tim Huelskamp of Kansas, naming the Republican majority leader of the Senate.

One immediate impact, however, might be to prolong Boehner's tenure. The Ohio Republican, who had intended to leave Oct. 30, said he would stay on "until the House votes to elect a new speaker."

The man most widely seen as a potential speaker in McCarthy's place immediately ruled it out.

"While I am grateful for the encouragement I've received, I will not be a candidate," said Rep. Paul Ryan of Wisconsin, the former vice presidential nominee who now chairs the Ways and Means Committee. But Ryan was under intense pressure to reconsider, including from Boehner and McCarthy himself.

"I would hope he would" run, McCarthy said of Ryan.

Establishment-minded Republicans expressed bitter frustration at the sway of the Freedom Caucus at a time when Republicans command their largest House majority in 80 years. And stark uncertainty lies ahead as lawmakers question how any candidate backed by mainstream Republicans will be able to prevail in the House.

It all comes with Congress in desperate need of steady leadership as major fiscal and budgetary deadlines loom, starting with the need to raise the government's debt limit to avoid a market-shattering default in a month's time.

"This is unprecedented to have a small group, a tiny minority, hijack the party and blackmail the House," said Rep. Peter King of New York.

McCarthy might have been able to eke out a win, but he said that's not how he wanted to become speaker. It's now unknown when the House GOP election will occur, and in doubt as to whether a scheduled Oct. 29 floor vote by both Democrats and Republicans will go forward.

McCarthy's two announced GOP rivals for speaker — Reps. Jason Chaffetz of Utah and Daniel Webster of Florida — lack widespread support in the House GOP, although Webster has the backing of the Freedom Caucus, whose members dismissed McCarthy as a clone of Boehner.

Numerous other names began to surface of possible candidates, and lawmakers were openly discussing the possibility of elevating a "caretaker" speaker to serve for a short time.

"You understand it could be a quick end to your political career," remarked Rep. Lynn Westmoreland, R-Ga., one of those discussed. He held up his cellphone to show calls coming in from McCarthy.

The Republicans' noontime meeting was adjourned moments after it began with McCarthy making his jaw-dropping announcement as his wife and kids looked on.

"Disbelief, from the surprise announcement by Boehner to the quick nature of this election to it now being postponed — it's uncertainty on top of uncertainty," said freshman Rep. Ryan Costello of Pennsylvania. "I've been here nine months, I've never seen anything like this. I'd bet you most other members who have been here 20 or 30 years would say the same thing."

Several Republicans were crying after McCarthy's announcement, lawmakers at the meeting said.

Underscoring the tumult, Rep. Reid Ribble, R-Wis., became the second lawmaker in a month to quit the Freedom Caucus.

Ribble, a McCarthy supporter, said in a statement that he has "a clear idea of the qualities a leader will need" to unite Republicans. Rep. Tom McClintock, R-Calif., quit in September, complaining that the caucus' tactics were backfiring and hurting the GOP.

Despite the pandemonium, the business of government continued, with committees holding hearings and the House convening to vote on a piece of energy legislation that passed on a largely party-line vote.

McCarthy, a 50-year-old from Bakersfield, California, in his fifth term in the House, is personable and friendly, popular with fellow lawmakers and known for his political acumen, if not his policy depth.

But his candidacy for speaker had gotten off to a rough start with a gaffe when he suggested the House's Benghazi committee was set up to drive down Hillary Rodham Clinton's poll numbers rather than search for the truth about the 2012 attacks in Libya that killed four Americans. He was roundly criticized and quickly backtracked, but the flub dogged him, giving ammunition to Democrats to discredit the committee ahead of Clinton's appearance Oct. 22 to testify.

Thursday morning, at a closed-door GOP candidate forum ahead of the elections, Rep. Dana Rohrabacher of California, a natural McCarthy ally, stood up and told McCarthy that he wouldn't be able to support him because of that comment, people present said.

McCarthy brushed off a suggestion that his decision had anything to do with a letter circulated earlier this week by Rep. Walter Jones, R-N.C., asserting that any candidate for leadership should withdraw from contention "if there are any misdeeds he has committed since joining Congress that will embarrass himself, the Republican Conference and the House of Representatives if they become public."

Jones has said the letter wasn't directed at anyone in particular. Asked whether it played a role in his decision McCarthy said: "Nah."

But the episode evoked memories of the shocking moment in December 1998, when Rep. Bob Livingston, R-La., astonished Washington by suddenly dropping his bid to replace Newt Gingrich as speaker. Livingston was the heavy favorite, but had been dogged by allegations that he had been unfaithful to his wife.

Livingston's announcement came as the House was debating President Bill Clinton's impeachment with its roots in Clinton's own infidelities.