Mr. Turull was the third candidate proposed by the main separatist parties since December, when they narrowly retained their parliamentary majority in a snap election called by Mr. Rajoy.

Last October, after separatist lawmakers declared independence, Mr. Rajoy used emergency constitutional powers to oust Mr. Puigdemont’s administration and place Catalonia under direct rule from Madrid. Hoping to end the separatist challenge, Mr. Rajoy then called the election, which instead left Catalonia in a political deadlock.

Since then, Mr. Rajoy has repeatedly called on the separatists to form a new government that recognizes Spanish sovereignty and is not led by one of the politicians indicted by Spain’s judiciary. After the failed attempt to elect Mr. Turull, the separatist parties now have two months to form a government or force Catalonia to hold a new election, a possibility that Mr. Rajoy said Friday that he hoped to avoid.

The case against Catalan separatists is now led by Judge Llarena from the Supreme Court, but two other courts, one in Madrid and another in Barcelona, are also investigating officials accused of civil disobedience and other offenses, including organizing the independence referendum held last October, even after it was declared illegal by Madrid.

Prosecutors want the main Catalan politicians to stand trial before the end of the year, but it is unclear whether Spain’s judiciary will be able to force the extradition of those who have fled the country. Judge Llarena is reactivating an arrest warrant that he dropped last year against Mr. Puigdemont and other former members of his cabinet, amid concerns that courts in Belgium, where he fled, would instead soften the charges against them.

Earlier this month, Mr. Puigdemont agreed to drop his bid for re-election. But he has since continued to defend the separatist cause and has traveled this month to Switzerland and Finland to attend conferences.

After the Supreme Court ruling, protesters gathered in downtown Barcelona on Friday evening, cutting off one of the city’s main avenues. The issue of independence not only has generated a conflict with Madrid but also has split Catalan society.

In December, separatist lawmakers won 47.5 percent of the votes, but that was enough for them to keep their majority of parliamentary seats, under a system of proportional representation that favors their dominance in rural areas.