Catalan separatist parties won a majority of the seats on Sunday in regional parliamentary elections that they billed as a plebiscite on secession from Spain. The result is set to intensify Catalonia's drive toward independence, despite fierce opposition from Spain's government under Prime Minister Mariano Rajoy. The separatist leaders have vowed to form a new regional government that will lead Catalonia to statehood within 18 months.

"We have a democratic mandate; we have won against all odds," Artur Mas, the Catalan leader, told supporters in central Barcelona on Sunday night as votes were still being counted. "Just as we, as democrats, would have accepted defeat, we ask that others recognize the victory of Catalonia and the victory of the Yes" bloc for independence, he added.

Still, the separatist parties failed to win a majority of the votes on Sunday and face significant legal hurdles in converting their secessionist ambitions into a breakup of Spain. The government in Madrid has repeatedly warned that any breach of the Constitution would be struck down by the courts and could lead even to the suspension from office of Catalan secessionist politicians.

Victory for Catalan Separatists

On the evening of an election in Catalonia, separatists celebrated as exit polls gave them a majority of seats in the region's Parliament. Pablo Casado, spokesman for Mr. Rajoy's Popular Party, said Sunday night at a televised news conference that "we will continue to guarantee legality and the unity of Spain." He called on Mr. Mas to resign or work to heal the divisions he had created within Catalonia. "Secessionism tried to split Spain but didn't succeed, but it did manage to divide Catalonia," Mr. Casado argued.

Even before Sunday's vote, the separatist issue had plunged Spain into its most serious crisis since June 2012, when Mr. Rajoy was forced to negotiate a European banking bailout in the midst of the euro debt crisis.

The secessionist drive has gained momentum in recent years, but Sunday's vote also showed the extent to which it had deeply split Catalonia's 7.5 million citizens. With 98 percent of the votes tallied, the separatist parties had won the most parliamentary seats and around 48 percent of the votes amid a record turnout.

The standoff between Mr. Rajoy and Mr. Mas started in 2012 as a financial dispute over the tax contribution that wealthy Catalonia should make to poorer regions of Spain. Mr. Mas then turned his frustrated demand for fiscal concessions into a full-fledged drive for independence.

After voting on Sunday, Héctor Carnet, 35, an information technology administrator, said he would not have imagined voting for independence three years ago. "I've come to see that it's better to go that way than stick with a Madrid government that hasn't offered us any decent alternative," he said.

But his wife, who declined to give her name, disagreed. "We need to build a stronger Europe rather than add new countries," she said. "I don't think it makes sense to fight for independence in the 21st century."

The regional parliamentary election was called by Mr. Mas, leader of Catalonia's governing Convergence party. He presented it as a proxy vote on independence after Convergence agreed with the other main left-wing separatist party to run a joint list of candidates.

The joint "Together for Yes" list won 62 of the 135 seats in the Catalan Parliament, according to the preliminary count. That will translate into a majority if the "Yes" leaders can form a coalition with a far-left separatist party known by its Catalan acronym of CUP. CUP, which won 10 seats on Sunday, has opposed Mr. Mas's public spending cuts and accused Convergence of widespread corruption after its founder admitted tax evasion last year.

Raül Romeva, leader of the "Yes" list, told supporters on Sunday that "nobody can say that we don't have legitimacy."

But it is likely to remain contentious that under the Spanish system of proportional representation, separatist parties managed to win the most seats without a majority of votes. Opponents of secession argued that if separatist leaders wanted Sunday's vote to be equated to a plebiscite, then votes counted more than parliamentary seats.

Opponents of secession have warned of significant economic problems on regional and national levels if Catalonia, which accounts for a fifth of Spain's economic output, breaks away. The president of the Spanish central bank recently said that Catalan banks would be cut off from the funding of the European Central Bank, which has been critical for Spanish and other financial institutions that were crippled by the euro debt crisis and unchecked property lending.

European leaders have also recently waded into the debate, aware that any unilateral secession by Catalonia could send the European Union into uncharted waters. The European Union's ability to produce a common response to crises has already been severely tested recently by a wave of migrants from Syria and other Middle Eastern and African countries. A Catalan secession could fuel the separatist claims of other European regions.

During a recent visit to Madrid, Prime Minister David Cameron of Britain suggested that if Catalonia seceded, it would have to reapply for European Union membership. Last September, Scots rejected independence in a referendum authorized by Mr. Cameron's government.

Sunday's vote took place two months before a national election that could also fragment Spanish politics, as two emerging parties threaten to help unseat Mr. Rajoy's Popular Party.

The left-wing party Podemos, while calling on Catalans to remain within Spain, supports a referendum on independence. The main opposition Socialist party has also pledged a constitutional change that could turn Spain into a federation.

According to preliminary results, Mr. Rajoy's Popular Party sunk to 11 seats, down from 19 in 2012, allowing instead the Citizens party to become the clear leader of the anti-secession opposition in the next Catalan Parliament. The Citizens party won 25 seats on Sunday, up from nine in 2012. The Catalan version of Podemos won 11 seats on Sunday, while the Socialists came in third, with 16 seats.

With a possible year-end overhaul of the national government also in mind, Mr. Mas and other separatist leaders talked Sunday night about a victory for their secessionist project, but without making clear whether or when a new Catalan government could declare unilateral independence.

Instead, Pedro Sánchez, leader of the Socialist party, underlined the failure of separatists to win a majority of votes and pledged to make a broader Spanish constitutional change to help reunite the country if the Socialists return to power in the national election.

"We have a Catalonia divided in two blocs, and the task of those who form the new government should be to heal these wounds," Mr. Sánchez said in a televised briefing from Madrid.