In a remarkable statement that seemed to cast doubt on American democracy, Donald J. Trump said Wednesday that he might not accept the results of next month’s election if he felt it was rigged against him — a stand that Hillary Clinton blasted as “horrifying” at their final and caustic debate on Wednesday.

Mr. Trump, under enormous pressure to halt Mrs. Clinton’s steady rise in opinion polls, came across as repeatedly frustrated as he tried to rally conservative voters with hard-line stands on illegal immigration and abortion rights. But he kept finding himself drawn onto perilous political territory by Mrs. Clinton and the debate’s moderator, Chris Wallace.

He sputtered when Mrs. Clinton charged that he would be “a puppet” of President Vladimir V. Putin of Russia if elected. He lashed out repeatedly, saying that “she’s been proven to be a liar on so many different ways” and that “she’s guilty of a very, very serious crime” over her State Department email practices. And by the end of the debate, when Mrs. Clinton needled him over Social Security, Mr. Trump snapped and said, “Such a nasty woman.”

Mrs. Clinton was repeatedly forced to defend her long service in government, which Mr. Trump charged had yielded no real accomplishments. But she was rarely rattled, and made a determined effort to rise above Mr. Trump’s taunts while making overtures to undecided voters.