ATHENS — Four years ago almost to this day, Greece came a breath away from leaving the euro. People formed quiet, somber lines outside banks to take out small amounts of cash, as a lockdown on the financial system barred them from accessing their savings. They stockpiled tinned food and toilet paper.

On Sunday, the leader who rallied Greeks to confront international creditors, but then reversed himself and gave in to their demands for austerity, was voted out of office. Prime Minister Alexis Tsipras, a former firebrand leftist, was defeated in a landslide.

Greeks turned instead to the resurgent center-right New Democracy party led by Kyriakos Mitsotakis, a Harvard-educated former banker and son of a 1990s prime minister. His party secured almost 40 percent of the vote and a comfortable majority of 158 seats in the 300-seat Parliament.

Mr. Tsipras’s party, Syriza, got about 31 percent of the vote — a stinging defeat for the prime minister personally and a bookend to what began as a social experiment, just as populist parties from the left and the right are on the ascent elsewhere in Europe.