The competition to claim Mr. Obama’s political mantle was the dominant theme of the night, given that the Democratic race has become so close in Iowa and New Hampshire.

Mr. Obama remains widely popular among party members, particularly in the state that Mrs. Clinton now needs to win more than ever: South Carolina, which votes on Feb. 27. Should she lose the first two nominating contests, Mrs. Clinton and her team believe she can regain political momentum in the South Carolina primary, in part because of her strong support among African-Americans there.

Mrs. Clinton repeatedly reiterated her support for Mr. Obama’s agenda, while Mr. Sanders tried to present himself as the bolder choice to build on Mr. Obama’s legacy. But she stymied him at times: When Mr. Sanders criticized Mrs. Clinton for accepting more than “$600,000 in speaking fees” from Goldman Sachs, she used the moment to portray Mr. Sanders as opposed to Mr. Obama on the issue of Wall Street regulation.

The third candidate in the Democratic race, former Gov. Martin O’Malley of Maryland, who is far behind in most polls, showed some new life at the debate as he reminded the audience that Mrs. Clinton had evoked the Sept. 11, 2001, terrorist attacks previously to explain her Wall Street donations when she was a senator representing New York.

“Now you bring up President Obama here in South Carolina in defense of the fact of your cozy relationship with Wall Street,” Mr. O’Malley said. If Mrs. Clinton was trying to make Mr. Sanders look less than qualified for the presidency, Mr. Sanders repeatedly tried to address doubts about his electability, which a new Clinton television advertisement has questioned. At one point, he rattled off some of his strong poll numbers, not unlike the leading Republican candidate, Donald J. Trump.

“When this campaign began, she was 50 points ahead of me,” he said. “We were all of three percentage points. Guess what? In Iowa and New Hampshire, the race is very, very close.”