Expected loss of ruling party’s parliamentary majority deals stunning blow to prime minister ahead of third term