Democratic front-runner Hillary Clinton aggressively prosecuted Sen. Bernie Sanders on issues from gun control to health care and fealty to President Obama at a presidential debate Sunday as she sought to puncture Sanders’s insurgent appeal and regain her footing after a difficult stretch.

Clinton put Sanders on the defensive through much of the two-hour debate, but a hoarse-voiced Sanders got in numerous digs. He accused Clinton of being too cozy with Wall Street and beholden to the financial industry. He noted that Clinton has accepted millions in campaign donations and hundreds of thousands in speaking fees from the financial sector.

With raised voices, interruptions and wonky examinations of one another’s voting records and policies, Sanders and Clinton battled over who had the more progressive or more workable solutions. Their exchanges were the most combative and personal of the campaign so far, reflecting the newly potent threat Sanders poses to Clinton in her second White House run.

The debate revealed a stark contrast between a status quo vision of pragmatism represented by Clinton and the lofty aspirations of the most leftward wing of the party represented by Sanders.

While Clinton pledged to work with both parties in Washington, Sanders insisted that progressive change will come only with a dramatic shake-up in the political system. “Nothing real will happen unless we have a political revolution,” he said.

The three Democratic presidential contenders engaged in heated exchanges on health care, gun control, former president Bill Clinton and other issues in Charleston, S.C. on Jan. 17. Here are the key moments from the two-hour debate in three minutes. (Sarah Parnass/The Washington Post)

One of the sharpest exchanges came over health care, an issue that has vexed the Democratic Party for decades, and one on which Clinton has tried to seize the high ground. Two hours before the debate in a graceful hall in Charleston’s genteel historic district, Sanders released details of his health-care plan, which if enacted would raise taxes.

The plan would cost about $1.38 trillion a year, according to the “Medicare for all” document he released. Sanders proposes to pay for his plan through a combination of premiums paid by employers and households, new income tax rates and other changes to the tax code, and savings from current health-care spending that he says the plan would achieve.

Clinton suggested that Sanders’s latest plan was unserious — “Again, we need to get into the details,” she said — and charged that in pursuing his goal of a single-payer system, Sanders would jeopardize Obama’s landmark Affordable Care Act.

“The Democratic Party in the United States worked since Harry Truman to get the Affordable Care Act passed,” Clinton said. “We finally have a path to universal health care. We’ve accomplished so much already. I don’t want to see the Republicans repeal it, and I don’t want to see us start over again with a contentious debate.”

Sanders delivered a snappy retort: “No one is tearing this up. We’re going to go forward.” He bemoaned that the costs of health care in the United States are far greater than in other industrialized nations like Canada and France and that his Medicare-for-all plan would bring necessary improvements.

Sanders said that some middle-class families would pay “slightly more” in taxes, an acknowledgment that advisers to Clinton quickly trumpeted on Twitter and elsewhere.

Throughout the debate, Clinton found ways to cast herself as the rightful heir and protector of the Obama legacy. On health care, she said she was the one to preserve the Affordable Care Act. On financial reform, she commended him for the Dodd-Frank bill regulating Wall Street. And on foreign policy, she recalled her days as secretary of state advising the president in the White House Situation Room.

The debate came 15 days before the Iowa caucuses on Feb. 1, a key test of both candidates’ strength and momentum. It was the last debate and probably the final face-to-face meeting for Clinton and Sanders before the Iowa contest, which has suddenly become a dogfight after several sleepy months during which the raucous Republican campaign drowned out the Democrats.

Long-shot candidate and former Maryland governor Martin O’Malley joined Clinton and Sanders for the debate sponsored by NBC News, YouTube, the Congressional Black Caucus Institute and the South Carolina Democratic Party.

The leading candidates also sparred over financial regulations. Sanders said Clinton was too friendly with Wall Street over two decades in national politics to be trusted to effectively crack down on the industry.

“Can you really reform Wall Street when they are spending millions and millions of dollars on campaign contributions and when they are providing speaker fees to individuals?” Sanders asked. “It’s easy to say, ‘I’m going to do this and do that,’ but I have doubts.”

The senator from Vermont said the financial system was “corrupt,” noting that it is “very strange that a major financial institution that pays $5 billion in fines for breaking the law, not one of their executives is prosecuted while kids who smoke marijuana get a jail sentence.”

Clinton said there was “no daylight” between their plans for the banking industry. She said that experts had determined her proposals were effective and strong, to which O’Malley interjected: “It’s just not true.” He said Clinton would not go far enough to punish financial institutions and their top executives.

Clinton used the exchange on financial regulations to drive a wedge between Sanders and Obama. She noted that Sanders in the past has criticized the president for accepting contributions from Wall Street and called the president “weak” and “dis­appointing.”

“I’m going to defend Dodd-Frank and I’m going to defend President Obama for taking on Wall Street, taking on the financial industry and getting results,” Clinton said.

Co-moderator Andrea Mitchell raised the issue of Bill Clinton’s extramarital affairs, asking Sanders why he has criticized the former president’s past transgressions.

Frustrated, Sanders said he “cannot walk down the street” without reporters asking him to attack Hillary Clinton.

“His behavior was deplorable,” Sanders said of Bill Clinton. “I’m going to debate Secretary Clinton and Governor O’Malley on the issues facing the American people, not Bill Clinton’s personal behavior.”

At that, Clinton nodded and smiled.

Clinton had held a sturdy lead of between five and 10 percentage points in Iowa for most of the fall, but her advantage has evaporated to a statistical dead heat. In New Hampshire, which votes second, Sanders appears to have a slight lead.

Sanders pointed to the polls, cracking a smile as he noted that when the campaign began Clinton had a roughly 50-point lead over the then-little-known senator from Vermont.

Under the new dynamic, Clinton faces heavy pressure to show she can hold off Sanders’s surge and avoid a replay of 2008, when then-Sen. Barack Obama surged ahead of her in Iowa. Sanders is also under pressure to offer more specifics on some of his policy proposals, as the self-described democratic socialist has come under heavier scrutiny.

“I have made it clear based on Senator Sanders’s own record that he has voted with the NRA, with the gun lobby numerous times” and against the Brady gun-control law, Clinton said.

“He voted to let guns go onto the Amtrak, guns go into national parks. He voted against doing research to figure out how we can save lives. Let’s not forget what this is about, 90 people a day die from gun violence in our country. That’s 33,000 people a year.”

Sanders replied evenly, “I think Secretary Clinton knows that what she says is very disingenuous.”

O’Malley, who signed sweeping gun laws as governor, interjected to say: “They’ve both been inconsistent when it comes to this issue. I’m the one candidate on this stage that actually brought people together to pass comprehensive gun safety legislation.”

Clinton has singled out Sanders’s 2005 vote for a bill that provided immunity for gun manufacturers, something she opposed as a senator from New York. Sanders initially defended his vote, but late Saturday he announced he supported legislation to repeal the bill. Sunday morning, Clinton slammed the shift as a debate-eve conversion and accused Sanders of a “flip-flop.”

Clinton also has called on Sanders to join her in supporting new legislation to close what some call the “Charleston loophole,” which allows gun buyers who would fail a background check to still purchase a gun in the event that the background system malfunctions. The loophole is how Dylann Roof was able to obtain the gun he allegedly used to kill nine people in last year’s shooting at the historic Emanuel African Methodist Episcopal Church, a few blocks from the debate venue in Charleston’s historic downtown.

Sanders said on ABC’s “This Week With George Stephanopoulos” that he would “take a look” at such legislation, which would give law enforcement more time to conduct criminal background checks on individuals looking to buy guns. He also touted his D-minus rating from the National Rifle Association as evidence that he is a staunch supporter of gun-control laws.

Clinton is well positioned in South Carolina, which votes Feb. 27. She was about 40 points ahead of Sanders here in polls taken in December, largely on the strength of African American Democrats. The debate here was held on the eve of Martin Luther King Day, and all three candidates invoked the civil rights leader in their opening remarks.

John Wagner in Charleston and Sean Sullivan in Washington contributed to this report.