MADRID — Spain took a step closer toward holding its third election in a year after Parliament on Friday rejected for a second time acting Prime Minister Mariano Rajoy’s bid to form a minority government and end the country’s eight-month political deadlock.

Rajoy’s bid was defeated by 180 lawmaker votes to 170, the same as in the first confidence vote Wednesday.

Parliament now has until Oct. 31 to produce a government or fresh elections will be called, possibly on Christmas Day.

Rajoy’s conservative Popular Party has been running a caretaker government following inconclusive elections in December and again in June. The party won the most seats in both but lacks votes in Parliament to win an obligatory confidence vote to form a government.

Rajoy has vowed to continue seeking support over the next two months to try again. Other leaders, such as the leading opposition Socialist party chief Pedro Sanchez could also try to form a government.

Rajoy, in office since 2011, needed an absolute majority in the 350-seat chamber in the first vote while a simple majority would have sufficed Friday. In both votes he could only count on the support of his Popular Party’s 137 lawmakers and 33 others from two smaller groups.

He had pressured the Socialists, who have 85 seats, to at least abstain and let a minority government be formed. But Sanchez argued his group, like others, could never support a politician they blame for high unemployment, political corruption and severe cuts in national health care and education.

Opinion polls indicate a third election might not produce significantly different parliamentary makeup. They also indicate most Spaniards are opposed to staging another election and want the parties to reach a solution.

The scene could change after Basque and Galicia regional elections Sept. 25 when deals between local party branches may alter allegiances at a national level and free things up.

The last two national elections produced greatly 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. The development 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.