Here are key moments from the third and final presidential debate between Democrat Hillary Clinton and Republican Donald Trump, Oct. 19, in Las Vegas. (Sarah Parnass/The Washington Post)

Here are key moments from the third and final presidential debate between Democrat Hillary Clinton and Republican Donald Trump, Oct. 19, in Las Vegas. (Sarah Parnass/The Washington Post)

At one of the last debates during the Republican primary, rival Ted Cruz turned to Donald Trump and asserted he was too cozy with Hillary Clinton to take her on — much less take her down — in a presidential debate. Trump shot back that he was “the last person that Hillary Clinton wants to face.”

By May, Trump was getting downright cocky. “I sort of wish we had more than three,” he boasted on CNBC.

But at the end of the third debate Wednesday night, it was clear that Cruz had been correct, if for different reasons: Trump proved to be no match for Clinton.

For the first hour or so of a competition here that he desperately needed to turn into a referendum on Clinton, Trump advanced a methodical contrast of their views on guns and the Supreme Court and offered an aggressive, if shaky, critique of Clinton’s record on immigration, abortion and other matters. But he appeared rattled at times by her jabs and then fell back into a habit that has tripped him up time and again: making the debate about himself and his controversial views.

“I will look at it at the time,” he said in a response to a question from moderator Chris Wallace about whether he would accept the results of the election, echoing his unsubstantiated claims on the campaign trail of a “rigged” contest. Later, he added: “I will tell you at the time. I will keep you in suspense.”

The Fix’s Aaron Blake breaks down the key moments of the third presidential debate on Oct. 19 between Hillary Clinton and Donald Trump. (Bastien Inzaurralde/The Washington Post)

The real estate businessman and reality TV star long billed himself as the ideal messenger to prosecute a devastating case against Clinton before tens of millions of onlookers — a political outsider with a knack for piercing insults who could sow serious doubts about her character.

Instead, during nearly 300 minutes spent debating Clinton over the past month, Trump repeatedly missed chances to communicate a clear case against her. Instead, he mostly shone a spotlight on his own weaknesses and stumbled through unforced errors — feeding concerns about his treatment of women, his readiness for the presidency and his temperament for the job.

[Fact checking and analysis of the final presidential debate]

For Trump, the debates have been at the center of the most destructive two-month period of his campaign, when he has faced multiple accusations of unwanted sexual advances against women and blowback over his vulgar comments on a hot microphone about forcing himself on women sexually. He now trails Clinton by a wide margin in nearly all national and battleground state polls, and party leaders fear it is too late for him to recover.

For the GOP, the debates have amounted to an enormous missed opportunity to mount its case against Clinton, which has been years in the making and which many Republicans were once confident would be their key to victory. The Republican nominee struggled throughout the debates to keep a consistent focus on Clinton rather than himself, just as he has in the rest of the campaign.

At times Wednesday night, Trump showed flashes of the debater many Republican leaders have been eager to see emerge. He landed a blow against her shift on trade and raised a recently revealed video showing a Democratic operative bragging about disrupting Trump rallies.

But for the most part, Trump was repeatedly on the defensive on issues that have dogged him throughout the year.

1 of 20 Full Screen Autoplay Close Skip Ad × Scenes from the third and final presidential debate in Las Vegas View Photos Hillary Clinton and Donald Trump go head-to-head during the final debate in Las Vegas. Caption Hillary Clinton and Donald Trump go head-to-head during the final debate before election. Oct. 19, 2016 Donald Trump and Hillary Clinton answer questions during the third and final debate at the University of Nevada at Las Vegas. Melina Mara/The Washington Post Buy Photo Wait 1 second to continue.

“I don’t buy boats, I don’t buy planes,” he said in response to a question about his charitable foundation, which has come under heavy scrutiny over its questionable practices.

[Winners and losers from the final debate]

Clinton seemed keen on getting under Trump’s skin by needling him with certain words. She said he “choked” during his meeting with Mexican President Enrique Peña Nieto by not pressing his proposal to build a wall on the southern border of the United States and make Mexico pay for it.

She later said Vladi­mir Putin preferred a “puppet as president of the United States,” referring to Trump’s repeated praise of the Russian president as a strong leader. “You’re the puppet,” he shot back.

“I never met Putin. This is not my best friend,” Trump said a few minutes later, while casting doubt on the finding by U.S. intelligence agencies that Russia is behind a series of hacks aimed at disrupting the U.S. elections.

When Trump emphasized his hard-line views on immigration and border security, he opened himself up to Democratic attacks when he remarked, “We have some bad hombres here, and we’re going to get them out.”

“‘Hombres’? The only bad hombre here is @realDonaldTrump and his racist, xenophobic rhetoric,” Catherine Cortez Masto, the Democratic nominee for a closely contested U.S. Senate seat in Nevada, wrote on Twitter.

In the hours leading up to Wednesday’s debate, Trump’s unpredictability flared up. He skipped his morning walk-through, according to a campaign aide. Details surfaced about his motley guest list, which ranged from President Obama’s estranged half-brother Malik Obama, to Leslie Millwee, who emerged in recent days to accuse former president Bill Clinton of sexually assaulting her more than three decades ago.

[The presidential debate: Can Donald Trump change his trajectory?]

Trump’s debate problems started at Hofstra University in New York on Sept. 26. For weeks leading up to the eagerly anticipated matchup, polls showed he was chipping away at the lead that Clinton had gained after the Republican and Democratic conventions. But he failed to capi­tal­ize, missing chance after chance to scold Clinton for labeling half of his supporters a “basket of deplorables” or to raise her use of a private email server as secretary of state.

He lingered in talk about the “birther” controversy that many Republicans wish he would have dropped long ago. Trump reignited feuds with comedian and actress Rosie O’Donnell and with Alicia Machado, the 1996 Miss Universe winner from Venezuela who has said Trump called her “Miss Piggy” and “Miss Housekeeping.”

Two days before the second debate, The Washington Post reported on a 2005 tape on which Trump can be heard bragging about forcing himself physically on women sexually. The comments were a focal point at the debate in St. Louis, where he apologized for the remarks but also dismissed them as “locker room talk.”

While Trump won some credit for putting Clinton on defense over her emails and the Clinton Foundation, the second faceoff was still in large part about him and he did little woo skeptical moderate voters.

In the week and a half since then, a series of women have come forward accusing Trump of making sexual advances without their consent. He once again denied all the allegations Wednesday night and tried to move past them, declaring that no one has more respect for women than he does.

But toward the end of the debate, Trump, who desperately needs to improve his image among female voters, attacked Clinton in a way that could further complicate the task.

“Such a nasty woman,” he said with disdain in his voice.