Spain's crisis over the future of Catalonia has deepened after an inconclusive regional election gave both sides in the independence debate cause to celebrate and left Prime Minister Mariano Rajoy scrambling to find a solution.

On Friday, Mr. Rajoy opened the door to negotiations with separatist leaders in Catalonia, but he insisted that any talks must be done within the constitutional framework. And he rejected a proposal by the exiled Catalan president Carles Puigdemont – who fled to Belgium to avoid charges of sedition – to meet outside of Spain. "I will make an effort to maintain a dialogue with the government that is formed from these elections, but also I will ensure that the law is upheld," Mr. Rajoy told reporters during a news conference in Madrid. "I hope that the new government will abandon unilateralism and will not be outside the law."

Thursday's election dealt a blow to Mr. Rajoy and threw into question his strategy of taking a hard line against the independence movement. Despite his efforts to thwart Mr. Puigdemont by invoking a form of direct rule over Catalonia and jailing several sovereigntist leaders, voters handed the three independence parties a slim majority of seats in the regional parliament. Mr. Rajoy's own party, the Popular Party, suffered its worst showing ever in a Catalan election, losing eight seats and electing just three members of Parliament. The results prompted calls by some European Union officials for Mr. Rajoy to start negotiating with the separatists.

"This is the moment, both for the separatists and for the Spanish government, to begin talks again," said Elmar Brok, a German member of the European Parliament and ally of Chancellor Angela Merkel. "This is not a broad mandate for Catalonian independence and that's why a serious effort should now be made to find a solution that is fair for everyone."

The election wasn't a major victory for the sovereigntists, either, and if anything, the results seemed to exacerbate the already sharp divisions in the region. While the three sovereigntist parties, including one led by Mr. Puigdemont, won a three-seat majority in the 135-seat parliament, their total was down from the last election. Meanwhile a pro-union party, called Citizens, took more seats than any other party, electing 35 MPs, and its leader, Ines Arrimadas, has emerged as a clear rival to Mr. Puigdemont.

"What we got is extreme polarization," said Jorge Galindo, a Spanish political analyst and commentator. "We have the same two blocks that we had before but now positions are a bit more polarized, if that's even possible … It's going to be a mess."

Mr. Rajoy will have to rethink his tactics, which so far have seen him give no ground to the separatists. He has been relentless in combatting Mr. Puigdemont ever since the Catalan leader declared independence in October after a controversial referendum that regional officials say won overwhelming backing for sovereignty, and that Mr. Rajoy called illegal. Although officials said 90 per cent of voters supported independence, only 42 per cent of those eligible cast ballots. Since then Madrid has suspended the regional parliament and jailed more than a dozen independence leaders. Mr. Rajoy used special powers under Spain's constitution to call Thursday's election, hoping voters would punish the sovereigntists. Instead, the independence block has emerged victorious and Mr. Puigdemont could retain his position as president even though he fled to Belgium to avoid prosecution for organizing the referendum.

"More than two million people are in favour of Catalonia's independence," Mr. Puigdemont said in Brussels on Friday, referring to the vote total for the three independence parties. "Recognizing reality is vital if we are to find a solution." Mr. Puigdemont added that he would welcome talks with Mr. Rajoy in Brussels and he called on Spanish authorities to drop the charges against him so he could take his seat in parliament.

Mr. Rajoy insisted on Friday that the legal process will continue and that politicians were not above the law, which means Mr. Puigdemont could be arrested if he returns. He also said that the direct rule measures will remain in place until Catalonia has a new government, which could take several weeks. When asked specifically about meeting Mr. Puigdemont, Mr. Rajoy replied: "I need to talk to whoever holds the presidency of the Catalan government. For that, he needs to take his seat in parliament, win a vote [in parliament] and be in a position to talk to me."

Story continues below advertisement

Story continues below advertisement

It's unclear how Mr. Puigdemont or the independence block will be able to govern. Technically, MPs can hold seats in parliament even if they are in jail or exile, but they must show up to cast votes. How that will happen remains uncertain.

"It's increasingly clear that it will be very difficult for President Puigdemont to come back to Catalonia and regain the seat he won [Thursday]," said Antoni Bassas, a political commentator in Barcelona. "At the same time, the Spanish justice system is moving forward against Catalan politicians and leaders, and that will be damaging for the dialogue we need between Madrid and Barcelona." Mr. Bassas added that Thursday's election also made it clear that despite some harsh conditions, the independence movement "is here to stay."