Image copyright Getty Images

This may have been the debate Donald Trump wanted, but it wasn't the one he needed.

With one last chance to make a pitch to the American public that he should be trusted with the presidency, the Republican nominee had to make efforts to expand his base of support.

He had to find a way to distance himself from the allegation that he has a history of sexual harassment.

He had to position himself as the change candidate - just days after a Fox poll showed that Hillary Clinton, whose party has held the presidency for eight years, was beating him on the question of who would "change the country for the better".

Instead, after roughly half an hour of something resembling an actual policy debate about the Supreme Court, gun rights, abortion and even immigration, the old Donald Trump - the one who constantly interrupted his opponent, sparred with the moderator and lashed out at enemies real and perceived - emerged.

He called Mrs Clinton a liar and a "nasty woman".

He said the women accusing him of sexual harassment bordering on assault were either attention-seekers or Clinton campaign stooges.

Image copyright AP

He said the media were "poisoning the minds" of the public. And, most notably, he refused to say whether he would accept the results of the election if he loses.

Mrs Clinton had her own moments where she was put on the defensive - on her emails, on the Clinton Foundation and on embarrassing details revealed in the Wikileaks hack.

The difference, however, is that Mrs Clinton largely kept her poise and successfully changed the topic back to subjects where she was more comfortable. It was, in fact, a master class in parry-and-strike debate strategy.

The key takeaway from this debate, however - the headline that Americans will wake up to read in the morning - will certainly be Mr Trump's refusal to back way from his "rigged" election claims.

That was what Mr Trump wanted to say, but it isn't something the American people - or American democracy - needed to hear.

More on the US election

The Russian gambit

Mrs Clinton's skill at deflecting attacks and baiting Mr Trump into unhelpful answers first was on display when moderator Chris Wallace brought up a line from one of her Wall Street speeches - revealed in the Wikileaks hack - that she endorsed a hemispheric free-trade and open-immigration zone.

After saying she was only talking about an open energy market - an assertion that seems somewhat questionable - she tried to turn the question into a discussion of whether Mr Trump would denounce the Russian government, which US officials have said is behind the cyber-attack.

Media playback is unsupported on your device Media caption Hillary Clinton: "He [Putin] would rather have a puppet as president"

Mr Trump actually called Mrs Clinton out on her attempted "great pivot" - but then he went on to get bogged down on the Russian issue.

He said he'd never met Mr Putin (although he boasted during a primary debate that he had talked with him in a television green room), and said that Mrs Clinton was a liar and the real Russian "puppet".

Oh, and this all came up when the debate topic was supposed to be immigration.

For more analysis, follow Anthony on Twitter and Facebook

A bad experience

Image copyright Reuters

Mrs Clinton's next chance to pull a rhetorical switch-a-roo came during the economic portion of the debate. After a discussion of their tax proposals - and a predictable exchange of allegations over who's cutting and who's raising them too much - Mr Trump went after Mrs Clinton on her past support of trade deals.

When she waffled a bit, he tried to tag her with a line he used in an earlier debate with some success.

Why didn't Mrs Clinton enact her economic reforms over her 30 years in the public sphere? Mr Trump asked.

"You were very much involved in every aspect of this country," he said. "And you do have experience. I say the one thing you have over me is experience, but it's bad experience, because what you've done has turned out badly."

The problem with reusing attack lines is that sometimes your opponent prepares a defence - and Mrs Clinton had a scathing response ready to fly.

She said that while she was defending children's rights in the 1970s, Mr Trump was defending himself against charges he engaged in housing discrimination against African-Americans.

When Mrs Clinton was speaking out for women's rights as first lady in the 1990s, Mr Trump was taunting a beauty contest winner about her weight. And when she was in the White House situation room watching the raid on Osama bin Laden's compound, Mr Trump was hosting a television reality show.

Media playback is unsupported on your device Media caption Hillary Clinton highlights her achievements

"I'm happy to compare my 30 years of experience, what I've done for this country, trying to help in every way I could, especially kids and families get ahead and stay ahead, with your 30 years," she said.

"I'll let the American people make that decision."

It was a scripted set-piece, yes, but it drew blood.

Women trouble

Quick on the heels of the exchange about experience came the question Mr Trump had to expect - but didn't appear ready for. What did he think of all the women who had come forward since the last debate to allege that, when it came to sexual harassment, Mr Trump's actions matched his candid words in that recently revealed recording?

The Republican nominee's response was that the women were either attention-seekers or Clinton campaign stooges and that the allegations have been "largely debunked" - which, when you think about it, isn't exactly a blanket denial.

Image copyright AFP

In the last debate, Mrs Clinton appeared to hold back a bit in her condemnation of Mr Trump on the topic.

This time - perhaps inspired by First Lady Michelle Obama's well-received speech condemning Mr Trump last week - was much sharper.

"Donald thinks belittling women makes him bigger," she said.

"He goes after their dignity, their self-worth, and I don't think there is a woman anywhere who doesn't know what that feels like. So we now know what Donald thinks and what he says and how he acts toward women. That's who Donald is."

Media playback is unsupported on your device Media caption Presidential debate: The moment Trump v Clinton turned nasty

Mr Trump's response, that no one respects women more than he does, was met by laughter in the debate hall and the nearby media hall.

Mrs Clinton brushed off his efforts to turn the topic to her private email server.

He may have lost this election even without the live-mic revelation two weeks ago, but it's becoming increasingly clear his campaign has been irreparably wounded by it.

Cracked foundation

During the presidential "fitness" portion of the debate, Wallace had some pointed questions for Mrs Clinton, as well.

He asked her to defend the Clinton Foundation against allegations it was a pay-to-play organisation that granted insider access to the state department in exchange for big-money donations.

Image copyright Getty Images

Mrs Clinton responded by defending the foundation's actions - noting its high ratings from non-profit watchdogs and its global health efforts.

Mr Trump called it a "criminal enterprise" - but then Mrs Clinton was able to push the conversation to Mr Trump's foundation, which has had its own share of controversies.

She noted that Mr Trump had used foundation money to purchase a six-foot portrait of himself. "Who does that?" she asked.

Mr Trump tried to defend himself, but Wallace wouldn't let him off the hook, asking him why he used charitable money to settle a fine levied on his Florida resort.

The Republican's response was only that the money had gone to charity.

An exchange on the Clinton Foundation could have been - perhaps should have been - a winning moment for Mr Trump. Instead, it was another opportunity for Mrs Clinton to knock him off his stride.

Tangled rigging

Image copyright Getty Images Image caption Watching the debate at a Democratic office in California

Mr Trump was already largely sunk at this point in the debate. Mrs Clinton had managed to dodge his most dangerous attacks and goaded him into the kind of badgering behaviour that had garnered him negative reviews after the first debate. He needed a clear victory and, at the absolute best, he had fought Mrs Clinton to a draw.

Then he was asked whether, despite his talk of rigged voting at his rallies this week, he'd follow his running mate's lead and pledge to accept the results of the election.

"I will look at it at the time," he said. "I'm not looking at anything now."

It was a comment that will launch a thousand headlines and dominate discussion in the days ahead.

It was also just the start of a full-spectrum tirade by Mr Trump against a media that "poisoned the minds of voters" and Mrs Clinton, who he said should have been prohibited from even running for the presidency.

Mrs Clinton's response was that the Republican's remarks were "horrifying".

She then deftly expanded her response to paint Mr Trump as a man who cries "rigged" whenever he faces a situation he doesn't like - whether it's the FBI decision not to prosecute her for her email server, his loss in the Iowa caucuses earlier this year, the lawsuit against his eponymous for-profit university or even his reality TV show's defeat at the Emmy Awards. ("Should have gotten it," Mr Trump piped in.)

Media playback is unsupported on your device Media caption US election 2016: Why debates are getting worse, not better

"He's talking down our democracy," she concluded. "And I, for one, am appalled that somebody who is the nominee of one of our two major parties would take that kind of position."

Talking to Republican officeholders in the media spin room after the debate, their discomfort with Mr Trump's statement was palpable.

Some explained it away as a tongue-in-cheek joke. Others said it was simply Mr Trump not wanting to consider defeat before Election Day.

The reality, however, is Republican politicians owe their positions - past, current and future - to the people's vote, and they rely on the legitimacy granted by opponents who concede when defeated.

Mr Trump has called American democracy into question - and when he shakes that particular tree, it's impossible to determine who might get crushed by falling branches.

More on the US election

Polls suggest Mrs Clinton is ahead nationally and in key battleground states.