– Donald Trump and Hillary Clinton clashed in deeply personal terms in the second presidential debate on Sunday night, accusing each other of mistreating women, and signaling that the final month of the race would be an extraordinarily ugly political brawl.

Before the debate, Trump’s campaign appeared to be spiraling out of control after the release of a 2005 recording in which he boasted in explicit terms about how his celebrity allowed him to sexually assault women without consequence.

Asked about the tape, which set off an avalanche of denunciations by dozens of Republicans saying they could no longer support him, Trump offered a tepid apology but dismissed his language in the recording as minor compared with the national security threats facing the country.

“This was locker room talk,” Trump said, adding that he was not proud of what he had said and that he had already apologized to his family and the country. “I have great respect for women. Nobody has more respect for women than I do.”

Clinton disagreed, arguing that the contents of the recording were more evidence that Trump was not fit to be commander in chief.

“What we all saw and heard on Friday was Donald talking about women, what he thinks about women, what he does to women,” Clinton said. “He has said the video doesn’t represent who he is. I think it’s clear to anyone who heard it, that represents exactly who he is.”

After that heated exchange, things grew more personal. Trump dug into former President Bill Clinton’s history of sexual misconduct and said that as president he would appoint a special prosecutor to investigate Hillary Clinton.

Hillary Clinton avoided discussing her husband, but made the case that Trump’s treatment of women was part of a larger pattern of intemperate behavior that he has shown toward Muslims, immigrants, people with disabilities and others.

Trump, who was criticized after the first debate for missing opportunities to bring up Hillary Clinton’s handling of classified material as secretary of state, came prepared this time. He reminded the audience of her missing emails repeatedly, and when she said that the country should worry if Trump were ever responsible for overseeing its laws, he was ready with a retort.

“Because you’d be in jail,” Trump said.

The testiness between the candidates could not have been clearer Sunday night, as Trump and Clinton continually spoke over each other.

When Clinton noted at one point that she had not interrupted Trump, he fired back: “Because you have nothing to say.”

A frustrated Clinton tried to twist the knife over Trump’s recent troubles, responding, “OK, Donald, I know you’re into big diversions tonight — anything to avoid talking about your campaign and how it’s exploding.”

A half-hour in, Trump and Clinton slowly shifted to substance, debating some of the finer points of health policy. Trump explained his proposal to repeal the Affordable Care Act and replace it with a privatized system in which people could shop for insurance across state lines. For her part, Clinton extolled the virtues of building on the law, President Barack Obama’s signature piece of legislation.

But even in the policy portion of the debate, Trump could not resist a personal dig.

“Bernie Sanders said that Hillary Clinton has very bad judgment,” he said. “This is a perfect example.”

That the debate would turn to the topic of sexual impropriety seemed inevitable heading into Sunday night.

Shortly beforehand, Trump held a brief news conference in St. Louis with three women — Paula Jones, Juanita Broaddrick, and Kathleen Willey — who allege that Bill Clinton sexually assaulted or harassed them during his years in office in Arkansas or as president. They were joined by Kathy Shelton, who was 12 when she was raped by a 41-year-old in Arkansas; Hillary Clinton represented the man, who ultimately pleaded guilty to a reduced charge.

Trump’s gambit, which was broadcast on Facebook Live, was intended to rattle Hillary Clinton before the debate, but it went against the advice from leading Republicans and even some of Trump’s loyalists that he resist the temptation of targeting women tied to Bill Clinton.

As Trump listened approvingly, the women briefly described their experiences and also defended Trump over his lewd remarks. At the invitation of the Trump campaign, the women were also seated in the debate hall, where Bill Clinton and his daughter, Chelsea, were in a front row.

Trump’s preparations for the debate were unfocused and halting over the weekend as the political fallout from his recorded remarks became a nearly all-consuming distraction. But by Sunday morning, even as Republican leaders pleaded with him to show more contrition, he and his campaign appeared increasingly defiant.

In a series of Twitter messages, Trump savaged those in the party who had renounced him, a troubling sign to some leading Republicans who had signaled that their future support for him would be based in part on how he responded to this crisis.

“So many self-righteous hypocrites,” he wrote of the defectors. “Watch their poll numbers — and elections — go down!”

Trump’s campaign took a similar approach, escalating a confrontation that could imperil him and other Republican candidates this year. In a set of talking points sent to supporters Sunday morning, Trump instructed his loyalists to assail the party leaders who had disavowed his candidacy as politicians guided only by self-interest, and he vowed to win without them.

“A lot of the people who are being so critical now are the same ones who doubted him before,” read the talking points, which were shared by a Republican strategist. “They are more concerned with their political future than they are about the future of the country. Trump won the primary without the help of the insiders, and he’ll win the general without them, too.”

The two-pronged assault pointed to an extraordinary showdown between the party’s increasingly isolated nominee and a leadership that fears that his candidacy is beyond repair.

But as Trump intimated in his Twitter post, other Republican candidates, by criticizing their own standard-bearer, risk both angering die-hard Trump voters in their districts and dampening overall turnout among those who might otherwise cast a ballot for the entire Republican ticket.

Trump’s son, Donald Jr., highlighted the disconnect between the party establishment and some conservative voters in a Twitter post of his own. He linked to a snap poll indicating that few rank-and-file Republicans thought Trump should withdraw from the race.

“Shows how out of touch Elite are that’s what this has always been about: GOP voters want the party to stand by Trump,” he wrote.

For the Clinton campaign, the news of Trump’s lewd remarks was a political gift, and a timely one, during debate preparations. The recording fit neatly into the argument that Clinton was already planning to press about Trump’s attitudes toward women, an issue on which she capitalized strongly at their first debate 13 days ago.

Clinton advisers say they would like nothing more than for a fight about gender to dominate the final four weeks of the presidential campaign. Several of these advisers said in interviews that they were confident Trump’s words about women would hurt him far more than any backlash Clinton might experience as a result of renewed attention to Bill Clinton’s extramarital affairs or her own behavior toward the women associated with him.

Trump’s campaign indicated that he would raise the subject of Clinton’s infidelities in the coming days, even though much of the Republican Party leadership has counseled him to avoid the topic. The campaign’s talking points instructed supporters to counter questions about Trump’s 2005 remarks by invoking Bill Clinton’s adultery.

“Bill Clinton treated women horribly, while Hillary Clinton bullied and smeared Bill Clinton’s accusers,” they read.

Trump appeared to be particularly fixated on the case of Juanita Broaddrick, the Arkansas nursing home operator who alleges that Bill Clinton raped her in 1978.

Appearing on NBC’s “Meet the Press” on Sunday, Rudolph W. Giuliani, the former New York mayor who has become one of Trump’s closest advisers, said that Trump would depict Hillary Clinton as an accomplice to sexual assault.

“Not Bill Clinton’s role,” Giuliani said, “but her role as the attacker.”

Hillary Clinton has never suffered politically for Bill Clinton’s affairs — in fact, sympathy for her may have been an advantage in her 2000 Senate race — and her advisers believe most voters will not blame her for anything she did to discredit the women who had been involved with her husband. Advisers to both campaigns say that recent private polling has shown Hillary Clinton gaining ground among women as well as independents, two groups that Trump’s campaign fears will reject him over his comments about using his star power to force himself on women and kiss and grope them.

Hillary Clinton had been gaining in national and swing-state polls even before the latest Trump controversy began Friday afternoon. She has fought Trump into a statistical tie in Ohio, where he appeared to have a small edge through September, and she has regained solid leads in Colorado and Pennsylvania, according to recent polls. She also has a small lead in the latest North Carolina polls and is running closely with Trump in Florida.

Her advisers’ chief concern was the revelation that she had told Wall Street executives, in paid private speeches in recent years, that she favored “a hemispheric common market with open trade and open borders” and saw the need “for both a public and a private position” when political deals were being made. Those remarks were in documents posted online Friday by WikiLeaks and apparently came from a hack of the email account of John Podesta, Hillary Clinton’s campaign chairman.

Anticipating questions about those speeches, Clinton prepared several possible answers over the weekend, the gist being that she opposed open borders and trade deals that were not in the interest of U.S. workers, and that her speaking fees from banks had not stopped her from proposing new regulations on Wall Street. Her advisers were confident that Trump’s troubles would overshadow criticism of her.