TOKYO — As recently as this spring, Shinzo Abe looked as if he was on track to become Japan’s longest-serving prime minister, no small feat in a country where the leadership sometimes seems to be equipped with a revolving door.

But a local election in Tokyo has put Mr. Abe’s longevity in doubt. Voters for the capital’s metropolitan assembly on Sunday resoundingly rejected candidates from Mr. Abe’s party, the Liberal Democrats, while electing all but one of 50 fielded by an upstart party founded by Tokyo’s popular governor, Yuriko Koike.

The victory for Tomin First, the party Ms. Koike established in January, was widely seen as a referendum on Mr. Abe as much as a vote of confidence in Ms. Koike.

For several months, Mr. Abe, who has been in office since 2012, has been dogged by influence-peddling scandals, as well as repeated bumbling by some members of his cabinet. He has also drawn criticism for pushing through a legislative vote on an anti-conspiracy bill that many said he had not sufficiently explained. As the prime minister campaigned for his party in Tokyo last Friday, a scrum of protesters shouted, “Abe, resign!”