Mrs. Clinton, who is comfortably ahead in polls of New York voters, seemed to relish taking swings at Mr. Sanders.

“Make no mistake about it — this is not just an attack on me, it’s an attack on President Obama,” Mrs. Clinton said about the criticism of her use of a “super PAC” and her acceptance of big-money contributions. As many audience members booed, Mrs. Clinton grinned a little before saying, “This is a phony attack that is designed to raise questions when there is no evidence or support to undergird the insinuations.”

Mr. Sanders needs a landslide victory in New York to improve his slim chances at the Democratic nomination, and throughout the debate he appeared on the hunt for any new advantage. He highlighted a recent report about the failure of banks to plan for their own demise as evidence that his regulatory plans, and not Mrs. Clinton’s, were tough enough to rein in bank executives. He pointed to some polls indicating that he would be a stronger opponent than Mrs. Clinton in a general election against Donald J. Trump if he wins the Republican nomination.

Mrs. Clinton showed a determination to deal a devastating blow to Mr. Sanders in the New York primary, and she sought to lay the groundwork on Thursday night with the issue of Israel, which evolved into one of the more memorable exchanges of the evening.

In New York, where candidates traditionally compete with one another to align themselves with Israel’s interests, it was startling to see a major Democratic candidate, Mr. Sanders, unapologetically challenge the actions of the Israeli government and call for evenhanded treatment of Palestinians.

“If we are ever going to bring peace to that region,” Mr. Sanders said, “we are going to have to treat the Palestinian people with respect and dignity.” He added, “That does not make me anti-Israel.”