Hillary Clinton and Senator Bernie Sanders clashed vividly over immigration reform, health care and Cuba during a contentious debate Wednesday as the two Democrats appealed to Hispanic voters and tried to outdo each other in assailing Donald J. Trump.

Mrs. Clinton, bruised by her surprise loss in the Michigan primary a day earlier, was on the attack throughout the debate as she sought to undercut Mr. Sanders’s momentum before the next round of primaries.

Aiming her remarks at viewers watching on Univision, a Spanish-language sponsor of the debate, Mrs. Clinton threw his past support for Fidel Castro and President Daniel Ortega of Nicaragua in Mr. Sanders’s face and repeatedly criticized him for opposing a 2007 bill that would have created a path to citizenship for millions of immigrants in the country illegally.

“We had Republican support,” Mrs. Clinton said. “We had a president willing to sign it. I voted for that bill. Senator Sanders voted against it.”

She refused to let up when Mr. Sanders explained that he thought the guest worker provisions in the bill were “akin to slavery.” Mrs. Clinton argued that she, Senator Edward M. Kennedy and Hispanic groups would never have supported such a bill. Her broadsides finally became too much for Mr. Sanders when she accused him of supporting “vigilantes known as Minutemen” on the border.

“No, I do not support vigilantes — that is a horrific statement, an unfair statement to make,” Mr. Sanders said. “Madam Secretary, I will match my record against yours any day of the week.”

Image

Sebastien de la Cruz, a mariachi singer, sang the national anthem before the Democratic debate on Wednesday, and the moderators introduced the two candidates in Spanish.CreditTodd Heisler/The New York Times

In their final debate before primaries in Florida, Ohio and other states on Tuesday, the two Democrats were a study in contrasts as they made stark appeals to the demographic groups they have come to prize.

Mrs. Clinton repeatedly aligned herself with the needs and concerns of immigrant families and stuck to her promise to “knock down barriers” in employment and housing, hoping these priorities would inspire Hispanics and African-Americans and deliver her landslide victories in Florida and North Carolina.

Mr. Sanders’s rallying cries against the “rigged economy” and “establishment politics” were aimed at liberals, young people, working-class white voters and independents who could be decisive for him in Ohio, Illinois and Missouri, his top targets next week.

He appeared confident to the point of cocky at times, claiming at one point that Mrs. Clinton had borrowed from his proposals to make public colleges free. “Thank you for copying a very good idea,” he said. He chortled when Mrs. Clinton accused him of not supporting clean energy ideas, and he muttered, “Come on,” when Mrs. Clinton refused to stop speaking.

He also showed he could throw a punch, such as when Mrs. Clinton questioned the cost of his Medicare-for-all plan, saying, “If it sounds too good to be true, it probably is.”

“What Secretary Clinton is saying is that the United States should continue to be the only major country on earth that doesn’t guarantee health care to all of our people,” Mr. Sanders said, drawing a stern look from his opponent.

“I do believe in universal coverage,” she fired back. “Remember, I fought for it 25 years ago.”

The debate in Miami came just three days after the candidates’ last face-off in Flint, Mich., and one day after Mr. Sanders was declared the winner of that state’s primary. His unexpected victory infused his campaign with excitement and fund-raising momentum: He was on track to raise $5 million in online donations in the ensuing 24 hours.

“Secretary Clinton prevailed upon the governor of New York, Eliot Spitzer, who wanted to do the right thing and provide driver’s licenses to those who were undocumented,” Mr. Sanders said. “She said, ‘Don’t do it,’ and New York State still does not do it.” He also noted that he had supported allowing children from war-torn Central American countries to enter the United States and asserted that Mrs. Clinton’s view was “send them back.”

“That is something that is not fair about what I said,” Mrs. Clinton said. “I did say we needed to be very concerned about little children coming to this country on their own, very often, many of them not making it, and when they got here, they needed, as I have argued for, legal counsel, due process, to make a decision.”

Both candidates, who consistently praise President Obama on most issues, vowed to end the mass deportations of his administration. They both flatly promised not to deport children.

Mrs. Clinton projected steeliness throughout the debate and did not seem fazed by her loss in Michigan, taking comfort in her accumulation of more of the delegates needed to win the Democratic nomination. She has a steadily growing delegate lead over Mr. Sanders in spite of his successes, because her margins of victory have been greater.

Yet she was careful to show that she was not taking the nomination for granted, even pushing back against a question about whether she had gotten ahead of herself in assuming she had all but beaten Mr. Sanders.

“I’m continuing to work hard for every single vote across our country,” Mrs. Clinton said. “I was pleased that I got 100,000 more votes last night than my opponent, and more delegates.”

Each candidate sought to be perceived as the more formidable challenger to Mr. Trump, the Republican front-runner.

Mrs. Clinton argued that Mr. Trump was promoting “un-American views” and promised to “take every opportunity to criticize” him. Later, she mocked his centerpiece proposal to build “a very tall wall, right, a beautiful, tall wall.”

Mr. Sanders argued that he could convince Democratic Party leaders and elected officials that “Bernie Sanders is the strongest candidate to defeat Donald Trump.”

But Mrs. Clinton and Mr. Sanders both sidestepped a direct question about whether they thought Mr. Trump was a racist, given his hostile comments about Mexicans and Muslims and his initial reluctance to disavow the support of the former Ku Klux Klan leader David Duke.

Mr. Sanders said he was confident that Americans would not elect Mr. Trump, and pointed out that Mr. Trump had been a leading skeptic of whether Mr. Obama was born in the United States and eligible to be president. Mr. Sanders noted that no one had challenged him over the fact that his own father was born in Poland.

“Nobody has ever asked me for my birth certificate,” Mr. Sanders said. “Maybe that has to do with the color of my skin.”

Both Democrats saw the debate as an opportunity to reach Latino voters not only in Florida, but also in Arizona, California, Illinois and other states with large Hispanic populations.

Asked whether he stood by his positive statements in the past about Mr. Castro and Mr. Ortega, Mr. Sanders sought to put the remarks in context but did not disavow them. Mrs. Clinton pounced.

“I just couldn’t disagree more,” she said. “If the values are that you oppress people, you disappear people, you imprison people, even kill people for expressing their opinions, for expressing freedom of speech, that is not the kind of revolution of values that I ever want to see anywhere.”

Mrs. Clinton was introspective when asked why many Americans do not trust her. “Obviously, it’s painful for me to hear that,” she said. “I am not a natural politician, in case you haven’t noticed, like my husband or President Obama,” she added. “I just have to do the best I can” and “hope that people see that I am fighting for them.”

Many of the questions to Mrs. Clinton were provocatively worded, especially those from Jorge Ramos of Univision. After playing a video in which the mother of an American killed in Benghazi, Libya, questioned whether Mrs. Clinton had told the truth about the attacks there, Mr. Ramos bluntly asked: “Did you lie to them?”

Mrs. Clinton was taken aback. “She’s wrong. She’s absolutely wrong,” she said. “When we had information we made it public, but then sometimes we had to go back and say, we have new information that contradicts it.”

Mr. Ramos also pressed Mrs. Clinton on whether she would drop out of the race if she were indicted on charges related to her use of a private email server as secretary of state. At first she ignored the question, but when the moderators followed up, she dismissed it curtly.

“Oh, for goodness — that is not going to happen,” she said. “I am not even answering that question.”