MADRID — A majority of Spanish lawmakers Wednesday rejected conservative party leader Mariano Rajoy’s bid to form a government, signaling Spain’s eight-month political deadlock is unlikely to end any time soon.

In an investiture vote following a two-day debate, Rajoy, the acting prime minister, was voted down by 180 lawmakers against 170 in favor, as had been expected.

He had needed a majority of 176 votes in the 350-seat Parliament but could count only on his Popular Party’s 137 lawmakers and the backing of 33 others.

Rajoy, 61, has a second chance Friday when he needs only a simple majority of votes cast. Still, all signs indicate he won’t pass that test either as no other party appears willing to back him or even abstain.

If no government is in place in two months’ time, Parliament will be dissolved again and Spain will have to hold its third election in a year. That vote could come on Dec. 25, Christmas Day.

Rajoy, who has been running a caretaker government following inconclusive elections in December and then again in June, opened the debate Tuesday, saying that Spain needed a government urgently and that a third election would be a disaster.

He had appealed to the leading opposition party, which has 85 seats, to at least abstain and let a minority government be formed.

But Socialist leader Pedro Sanchez lashed out at Rajoy’s record in government since 2011, saying Socialists could never support those they blame for high unemployment, political corruption and recent severe cuts in national health care and education.

Rajoy has said he intends to keep trying to muster support over the next two months to avoid a third election.

The last two elections both produced fragmented parliaments with the rise of two new groups — the far-left Unidos Podemos alliance, which came in third, and the fourth-place business friendly Ciudadanos party. That development effectively ended Spain’s traditional two-party political system of the Popular Party and the Socialists. Spain has never had a coalition government and the country’s political elite are struggling with the idea of negotiating deals.