MOUNT PLEASANT, S.C. — Mark Sanford smiled. He shook hands, posed for photographs and drove himself around his district on Election Day. He ordered a chocolate milkshake.

But all day, after all these years as a governor and a congressman, he seemed to know what might be coming: his first concession speech. So it came to be in a crowded restaurant here on Tuesday night, hours after he had been openly mocked by President Trump, then knocked aside by a rival who vowed a close alliance with the White House. Mr. Sanford, a politician first sent to Washington as an insurgent of one era, was toppled in a different moment by a different kind of renegade.

“We are to cower before the people who elected us, and I get their verdict tonight,” Mr. Sanford said, reading from scribbled notes on a legal pad, as it became clear he would lose his House race against Katie Arrington in South Carolina’s Republican primary.

Even for a politician accustomed to humiliations — his marital infidelity and ill-fated, infamous trip to the Appalachian Trail, which was actually Argentina, still proved ripe for jabs this campaign — Mr. Sanford’s political unraveling in South Carolina was a striking comedown that somehow seemed both impossible and inescapable.