Presidential hopeful Hillary Clinton on Sunday cast herself as President Obama’s natural heir on guns, health care and the economy in the final debate before Iowa’s caucuses, but Sen. Bernard Sanders said it’s time for Democrats to push further, saying the country needs a “political revolution” to break the power of big corporations.

Mrs. Clinton accused Mr. Sanders of betraying Mr. Obama by seeking a primary opponent for him in 2012, and calling the president weak on tackling Wall Street. And she said Mr. Sanders‘ new plan for government-sponsored universal health care would undo the advances of Obamacare, which she said she would defend and expand.

Mr. Sanders denied that he’s an enemy of Mr. Obama, but embraced the charge that he wants to move beyond the president’s agenda, saying more must be done to break the power big banks and the wealthiest have over Washington.

“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?” he said, pointing to $200,000 he said Mrs. Clinton collected in 2013 to deliver a speech at investment giant Goldman Sachs.

“It’s easy to say I’m going to do this and do that, but I have doubts when people receive huge amounts of money from Wall Street,” he said.

Facing off in Charleston, South Carolina, in a prime-time debate aired on NBC, the candidates — with former Maryland Gov. Martin O’Malley rounding out the field — drew some of their sharpest distinctions year, with the surging Mr. Sanders facing increasing scrutiny over his past stances and future plans.

Mrs. Clinton came out swinging at the top of the debate, saying Mr. Sanders has benefited from help from the National Rifle Association, and that makes it impossible for him to pass gun control.

“He has voted with the NRA, with the gun lobby, numerous times,” she said. “He voted for immunity for gunmakers and sellers. There is no industry in America that was given the total pass the gunmakers and gun dealers were, and that needs to be reversed.”

Mr. Sanders, however, said he has a D-minus rating from the NRA, and said he can be the bridge-builder the country needs on the issue.

He’s taken heat for his 2005 vote to grant gun manufacturers immunity from liability lawsuits. Over the weekend he said he would now support legislation to eliminate that liability, and at the debate Sunday he said he “will support stronger provisions.” He also said Mrs. Clinton is politicizing the issue.

“This should not be a political issue,” he said. “What we should be doing is working together, and, by the way, as a senator from a rural state that has virtually no gun control, I believe I am in an excellent position to bring people together.”

“They’ve both been inconsistent when it comes to this issue,” he said, arguing he’s got a track record of winning strict gun control legislation from the legislature during his eight years as governor.

While Mr. Sanders was the focus of the debate, Mr. Obama’s shadow loomed large — particularly after his Tuesday State of the Union address, where he looked beyond this year’s policy fights and tried to lay out the philosophical decisions that face voters in November.

Mrs. Clinton sought to cloak herself in his calls to surmount political divisions, saying she will be the unifying president the country needs.

“I would be working in every way that I knew to bring our country together. We do have too much division, too much mean-spiritedness,” she said. “We need to do it together.”

Mr. Sanders, though, said he’s hoping to lead a “political revolution” in the U.S. that would challenge the power he said the wealthy and big corporations have over politics.

“This campaign is about a political revolution, not only to elect a president but to transform this country,” said Mr. Sanders, a self-described socialist who caucuses with the Democrats in the U.S. Senate.

Mr. O’Malley almost didn’t make the stage for the debate, with his polling in Iowa, New Hampshire, South Carolina and nationally falling below the 5 percent threshold of support NBC had set for participants. But the network relented and allowed him in nonetheless.

The former governor’s chief argument has been that his experience as a chief executive trumps that of the other two, who amassed most of their own records as legislators.

But Mr. O’Malley has stalled, proving unable to win over any of the support defecting from Hillary Clinton’s campaign. Instead, those voters are turning to Sen. Bernard Sanders, who has won them over with questions about Mrs. Clinton’s commitment to reining in what many Democrats see as the unchecked power of big banks.

Mrs. Clinton continues to hold a significant lead nationally, though she’s lost her advantage in both Iowa and New Hampshire. The latest RealClearPolitics.com average of polls gives her a 4 percentage point lead in Iowa, and gives Mr. Sanders a 6-point lead in New Hampshire.

Some analysts say Mr. Sanders‘ surge in the polls can be attributed to the fact that he’s widely seen as more passionate than Mrs. Clinton.

“He has a certain genuineness and appeal that she doesn’t,” said Dave Woodard, a political science professor at Clemson University.

The poll numbers have spurred Mrs. Clinton and her allies, and left them looking for ways to dent the rise of the Vermont senator.

One major area of dispute is over health care. Mr. Sanders strongly supports a Medicare-for-all health care system, and on Sunday night released the long-awaited details of his socialized medicine plan. The proposal relies on massive tax increases on the rich to pay for the $1.38 trillion-per-year system.

Mrs. Clinton, meanwhile, says she supports the concept of universal health care but believes Democrats’ No. 1 priority must be protecting the Affordable Care Act at all costs.

“To start over again with a whole new debate is something that I think would set us back,” she said in the debate.

Mr. Sanders argues Obamacare was just a first step, but said it left tens of millions of Americans still without coverage — and leaves too much power in the hands of health and drug companies.

“We are spending far more per person on health care than the people of any other country,” he said.

Mrs. Clinton has charged that Mr. Sanders‘ plan necessarily would raise taxes on middle-class families — a claim confirmed by Mr. Sanders plan itself, which would impose a 2.2 percent income-based tax on families making more than $28,800, in addition to other tax increases on individuals and businesses.

Sunday night’s debate, organized by the Democratic National Committee, comes as Mr. Sanders has kept alive a lawsuit against the party organization.

Mr. Sanders on Friday said he does not intend to pursue a lawsuit against the DNC over his campaign’s access to voter data files, but he kept the case open anyway in an attempt to hold the DNC’s feet to the fire.

In December DNC Chairwoman Debbie Wasserman Schultz barred the Sanders campaign from accessing Democratic Party voter files after Sanders staffers were caught snooping through Mrs. Clinton’s files on the DNC’s system.

Mr. Sanders has apologized for the incident, and his campaign’s access was restored quickly after he filed the lawsuit.