NASHVILLE — President Trump tried to cast Joe Biden as a ­scandal-plagued politician who had failed over decades in office, and Biden sought to portray Trump as a demagogue who criminally abused immigrants and mishandled the coronavirus pandemic as the two presidential contenders counterpunched on a wide range of policy issues in their second and final debate.

With the two candidates electronically muted for portions of the night, the constant interruptions from the first debate were replaced by a clearer contrast between their competing views for the country and more sharply defined exchanges of attacks and retorts.

When Trump tried to accuse Biden of making money from China, the former vice president pointed out that the president has a bank account in the country and has failed to disclose his income tax returns despite promises to do so.

When Trump argued that stock markets would crash if Biden were elected, Biden responded with his signature line contrasting the gains of Wall Street vs. the cratering Main Street economy.

And when Trump sought to paint Biden as a puppet of socialist forces, his opponent pushed back with a forcefulness that has been absent from much of his campaign. "He's a very confused guy. He thinks he's running against somebody else," Biden said. "He's running against Joe Biden. I beat all those other people because I disagreed with them."

One of the most heated moments of the night focused on Trump's policy of separating migrant children from their families at the border. Advocates have been unable to locate the parents of 545 children who were separated at the border.

Trump responded by asserting that the separated children had been "so well taken care of" and pressed moderator Kristen Welker of NBC to ask Biden: "Who built the cages?" implying it was the Obama administration. Biden, appearing the angriest he had been the entire debate, shook his head and said the family separations had made the United States the laughingstock of the world.

"It's criminal! It's criminal!" he declared.

At the end of the night, there was little sense that the incumbent president trailing significantly in the polls while overseeing a deadly pandemic and a crushed economy had done much to change his fortunes for the better.

Instead, Biden came to the debate with a well-rehearsed cache of opposition research, jabbing Trump over his record on health care, the coronavirus, race relations, the economy, immigration and more. Trump was pushed repeatedly on his record, including areas like health care, where he has failed to deliver on his promises.

At times Trump found himself struggling to respond to attacks on a wide range of policy issues, and on the issue of character — which Biden brought up repeatedly.

"There's a reason why he's bring up all this malarkey," Biden said after a particularly contentious exchange in which Trump brought up a number of unsubstantiated allegations of family corruption.

Turning to face the camera, Biden said, "He doesn't want to talk about the substantive issues. It's not about his family and my family. It's about your family. And your family's hurting badly."

Trump rolled his eyes and mocked Biden for turning the conversation to families like a "typical politician."

The exchange was indicative of the tense 90-minute debate at Belmont University in Nashville, which took place just 12 days before Election Day.

When Trump's initial allegations of corruption by Biden failed to set the tone of the debate, the president instead retreated his campaign's other main attack line, repeatedly describing Biden as a failed politician.

"He's been in government 47 years, he never did a thing," Trump said at one point.

"Why didn't he do it four years ago?" Trump said at another point, arguing that his own entry into politics was a result of Biden's failures. "I ran because of you."

While the night featured a number of sharp attack lines, it was less combative and acrimonious than the first debate, when near-constant interruptions and acerbic crosstalk led to the addition of a mute button by the Commission on Presidential Debates.

With Election Day nearing and with millions of Americans lining up daily to cast early ballots, the debate loomed as potentially critical for both candidates.

Trump, who has consistently trailed Biden nationally and in key states, came into the debate at Belmont University intent on making up ground. Privately, aides had urged Trump to tone it down this time after he was responsible for three-quarters of the interruptions in the first debate, which prompted the change in the rules muting each candidate’s microphone while the other responded to questions.

Biden’s campaign said the former vice president was determined to focus on issues such as the coronavirus pandemic, health care and the economy that it deems more important to voters, no matter Trump’s tone or emphasis.

“The debate is a test of presidential temperament,” Biden senior adviser Symone Sanders said in a briefing call with reporters Thursday afternoon. “The question isn’t the mic button. It’s whether Trump is coming for a serious discussion of his records and plans for the future, or more antics and distraction. Joe Biden will be prepared either way.”

Within the first several minutes of the debate, it was apparent both candidates were trying to refrain from interrupting the other.

“I’d like to respond if I may,” Trump said at one point, adding “thank you” when he was acknowledged by Welker.

The effort, however, appeared increasingly torturous as the debate progressed, with Trump grimacing and shaking his head and Biden gritting his teeth and stifling laughter as they waited for the other to finish.

The backdrop to the debate — and to the election itself — is the global pandemic that is worsening after leaving more than 222,000 Americans dead and upending the nation’s economy. Trump’s handling of the crisis is a top reason his standing in the polls has been so dire over the past several months — and his lack of introspection after contracting the virus himself has alarmed some advisers who worry that his defiant approach is turning off the voters he needs to prevail.

As Trump tried to continue playing down the virus — “We’re rounding the turn,” he said — Biden pressed him repeatedly over the death toll.

“Anyone responsible for that many deaths should not remain as the president of United States of America,” Biden said.

From the earliest moments, the contrast in the debate was clear. Biden walked in wearing a mask, while Trump walked in without one. Trump has previously mocked Biden for wearing a mask and equivocated on the usefulness of face coverings.

Early in the debate, Trump sought to make good on promises from his campaign that he would prosecute the case against Biden over his son Hunter’s alleged foreign business deals. The president accused Biden of being a “corrupt” politician and claimed without evidence that he had been paid $3.5 million from Russia.

“I think you owe an explanation to the American people” Trump said, turning to Biden. “I think you have to clean it up and talk to the American people — maybe you can do it right now.”

Biden offered an unequivocal denial, saying “I have not taken a penny from any foreign source at any time in my life,” and then turned the tables on the president.

He attacked Trump for having a bank account in China, and criticized Trump for doing hotel deals in foreign countries while not releasing his tax returns.

“What are you hiding?” Biden said. “Foreign companies are paying you a lot.”

The subject of race also prompted a clash. Several times Trump insisted he was “the least racist person in this room” and falsely claimed that he has done more for the Black community than any other president before him, with the “possible” exception of Abraham Lincoln.

Biden, in turn, gestured toward Trump and retorted: “ ‘Abraham Lincoln’ here is one of the most racist presidents we’ve had in modern history. He pours fuel on every single racist fire, every single one.”

Biden ran afoul of the facts at times as he made his case against Trump. At one point, he claimed that no one lost their health insurance during the Obama administration, which is not true. He also appeared to apologize for the immigration record of the Obama administration, which included large numbers of deportations and no comprehensive legislation to help undocumented immigrants. “We made a mistake,” Biden said. “It took too long to get it right.”

Biden sought to clarify after the debate his statement that his goal was to get rid of the oil industry — which may reverberate in swing states. “We’re not going to get rid of fossil fuels,” he said. “We’re going to get rid of subsidies for fossil fuels.”

But Trump through the night repeated regular falsehoods, which garnered either a shake of the head, a firm “no” or a correction from Biden.

For all the audience the debate was expected to attract, its political impact may be muted somewhat by the record level of early voting. More than 45 million Americans have already cast ballots, according to a tally by political scientist Michael McDonald of the University of Florida. The number of votes cast amounts to more than a third of all votes counted in 2016.

Biden, who spent much of the week preparing for the debate at his Delaware home, got a boost Wednesday from former president Barack Obama, who traveled to Philadelphia for a drive-in rally and delivered a speech assailing Trump as an unserious and unprepared commander in chief “incapable” of performing his duties.

The dichotomy in campaign focus was also apparent in the guests each candidate invited to the debate. Biden’s guests at the debate were Zweli and Leonardo Williams, restaurant owners from Durham, N.C., who have been hit hard by “this administration’s failed response to the covid-19 pandemic,” Sanders, Biden’s senior adviser, said.

Late Thursday afternoon, Trump’s campaign announced it had invited Tony Bobulinski, a former associate of Biden’s son Hunter. For the past week, the campaign and the president’s allies have been aggressively pushing a New York Post report relying on emails Hunter Biden purportedly exchanged with business partners and officials at a Ukrainian gas company, alleging that the younger Biden gave one colleague “an opportunity” to meet Joe Biden. The Biden campaign said the vice president’s schedule indicated no such meeting took place.

The Washington Post has not been able to independently verify the emails. The Post has on multiple occasions asked presidential attorney Rudolph W. Giuliani and former adviser Stephen K. Bannon, who helped make the materials public, for copies of what they allege is Hunter Biden’s hard drive but has received no response.

After the debate, Biden was scheduled to return to Delaware for a speech Friday and travel to Pennsylvania on Saturday to campaign in Bucks and Luzerne counties. Trump plans to vote in Florida on Saturday and had scheduled multiple rallies in several battleground states this weekend.