Populists on both the right and the left turned the prime minister's unpopularity to their advantage.