Austin, Tex. — Richard M. Nixon, the first president to resign from office, was hardly a beacon of moral integrity. Nor was Nixon above demagogy on the campaign trail, infamously fanning the flames of Communist paranoia during the McCarthy era by unjustly painting his opponent in his 1950 Senate race, the California congresswoman Helen Gahagan Douglas, as the “Pink Lady.”

But the 37th president, as controversial as he was, offers a good example for Donald J. Trump on the importance of putting the country ahead of one’s ego and personal ambition on Election Day.

When Mr. Trump, amid his claims that the voting process is rigged, was asked in Wednesday’s debate if he would accept a losing result in the coming election, he responded by spitting in the face of American democracy. “I will tell you at the time. I’ll keep you in suspense,” he said glibly, as though presaging a reality-show cliffhanger. The next day he told an audience in Ohio that he would accept the results of the election — “if I win.”

He would do well to look at the election of 1960, which pitted Nixon, the Republican presidential nominee and sitting vice president, against his Democratic rival, the Massachusetts senator John F. Kennedy. The two candidates waged admirable campaigns, which included squaring off in four substantive, widely watched debates, culminating with the election on Nov. 8.