By John Whitesides and Amanda Becker

CHARLESTON, S.C. (Reuters) - Democratic White House candidate Bernie Sanders went on the offensive against front-runner Hillary Clinton on Sunday in the most contentious of their four presidential debates, accusing her of cozying up to Wall Street and misrepresenting his stance on healthcare and guns.

Reflecting Sanders' rise in opinion polls, the two battled with new urgency over who was best suited to lead Democrats in the November election. Sanders cast himself as the outsider who would lead a political revolution, while Clinton touted her experience and embraced President Barack Obama's legacy.

In their last televised debate before Iowa's caucuses launch the nominating race on Feb. 1, Clinton raised questions about the self-styled democratic socialist's positions on Wall Street reform, healthcare and gun control.

Sanders pushed back at every turn. He painted Clinton as a defender of the status quo who accepted hundreds of thousands of dollars in speaking fees as a former secretary of state from Wall Street backers.

"I don't take money from big banks. I don’t get personal speaking fees from Goldman Sachs," the U.S. senator from Vermont said, adding, "I have huge doubts when people receive money from Wall Street."

He referred to his rising poll numbers in the early voting states of Iowa and New Hampshire, where he has pulled even or ahead of Clinton, saying he believed he could expand his number of supporters to include more African-American voters. He noted that when his presidential campaign began, Clinton was 50 percentage points ahead of him in the polls.

"Guess what: In Iowa, New Hampshire, the race is (now) very, very close," Sanders said.

The debate followed a week of rising tension between the two leading candidates. Sanders was noticeably more animated that in previous debates, sometimes grimacing and shaking his head during Clinton's answers.

Former Maryland Governor Martin O'Malley, who lags badly in polls, was often a bystander although he joined Sanders in criticizing Clinton's Wall Street ties.

Story continues

Clinton said she would build on Obama's agenda, accusing Sanders of voting to deregulate the financial market in 2000 in a way that led to the central causes of the financial collapse of 2008 that pitched the U.S. economy into a deep recession.

Clinton tried to undercut Sanders' support among supporters of Obama, who remains a popular figure in the Democratic Party.

"He's criticized President Obama for taking donations from Wall Street. And President Obama has led our country out of the Great Recession," she said.

"Senator Sanders called him weak, disappointing, he even in 2011 publicly sought someone to run in a primary against President Obama."

HEALTHCARE SPAT

Clinton pounced on Sanders' "Medicare-for-all" plan that was announced just hours before the debate after Clinton had criticized Sanders for refusing to explain how he would pay for the proposal.

The former secretary of state, former U.S. senator and wife of former President Bill Clinton said Sanders' healthcare plan would undermine Obama's signature Affordable Care Act at a time when Republican legislators were still trying to repeal and replace it.

"I have to say I’m not sure whether we’re talking about the plan you introduced tonight or the plan you introduced nine times over 20 years," she told Sanders. "But the fact is we have the Affordable Care Act. ... We have already seen 19 million Americans get insurance."

Sanders said he wanted to build on the Obama law by making health insurance more affordable.

"Nobody is tearing this up," he said, referring to the program popularly known as Obamacare. "We're moving forward."

The debate was held across the street from the Charleston church where a white gunman killed nine black worshippers in June, and Clinton made reference to the incident while accusing Sanders of being weak on gun control.

She welcomed his decision on Saturday night to back a bill in Congress rescinding portions of a law giving gunmakers immunity from lawsuits, but said his record showed a more lenient attitude toward the demands of the powerful National Rifle Association (NRA) gun lobby.

Sanders defended himself, saying he has a strong record on trying to prevent guns from getting into the wrong hands and standing up to the NRA.

Sanders supporters watching in Manchester, New Hampshire, said he seemed more engaged than in past debates. "I thought that Bernie was much more prepared," Chris Haigh, 66, said.

Sanders has pulled into a statistical tie with Clinton in recent polls in Iowa, whose caucuses are the first contest in the race to pick a nominee for the November election. He also leads Clinton in the next state to vote, Vermont neighbor New Hampshire, on Feb. 9, according to polls.

After those two states, the race moves to Nevada and South Carolina, which have more diverse voting populations and where polls show Clinton leading. On March 1, or "Super Tuesday", voters in 11 states, many of them in the South where Clinton has big poll leads, will cast primary ballots.

(Additional reporting by Alana Wise and Luciana Lopez; Writing by Steve Holland and John Whitesides; Editing by Mary Milliken and Jonathan Oatis)