In Sunday’s vote, the prime minister hoped to gain support from anger over a housing crisis but is now at risk of being ousted by conservatives and the far right.