Spain's Constitutional Court on Wednesday revoked a resolution by Catalonia's parliament that declared the start of a secession process in the wealthy northeastern region, sparking a defiant reaction from the local government.
The motion, passed last month, calls on Catalonia's regional assembly to start drafting laws within 30 days to create a separate social security system and treasury, with a view to completing independence in 18 months.
It also declares that the parliament of Catalonia is "sovereign" and not subject to decisions made by Spanish institutions.
Conservative Prime Minister Rajoy immediately filed suit at the Constitutional Court, which temporarily suspended the resolution last month while it considered legal arguments.
In a ruling shared by all 11 judges, the court on Wednesday ruled the motion "violates constitutional norms" which "affirm the unity of the Spanish nation."
Rajoy hailed the decision.
"For the majority of Spaniards, who believe in Spain, in national sovereignty, this pleases us greatly," he said.
But Catalonia's regional government quickly rose up in defiance, saying the resolution was here to stay.
"The content of this declaration, approved by an absolute majority, is to remain unchanged no matter how many sentences the Spanish Constitutional Court issues," government spokeswoman Neus Munte said.
The ruling comes just two days before the official start of campaigning for general elections.
The December 20 vote will see a stiff challenge to Rajoy's Popular Party from two new parties on the left and right as well as from the main opposition Socialists.
The Popular Party is presenting itself as the guarantor of national unity and of Spain's economic recovery after the country in 2014 came out of five years of recession or zero-growth.
The pro-independence camp won an absolute majority in Catalonia's 135-seat regional assembly for the first time in local elections in September but got only 48 percent of the popular vote.
Catalan leaders elected in September have vowed to ignore the rulings of the Constitutional Court.
While they banded together to pass the secession resolution, pro-independence parties still have not agreed on the formation of a new Catalan government two months after the election.
Polls show that most Catalans support a referendum on independence, but are divided over breaking away from Spain.
Opposition to Catalan independence stands at 48.2 percent while 46.6 percent are in favour, according to a Centre for Opinion Studies poll published Wednesday.
That is virtually unchanged from October when the polling firm found 47.8 percent of Catalans opposed independence while 46.7 percent were in favour.
Catalonia, a northeastern region of 7.5 million people which represents nearly a fifth of Spain's economic output, already enjoys a large degree of autonomy in education, health and policing.
But it is insisting on even greater autonomy, particularly where taxation is concerned, estimating that it gives more to the central government than it receives.
A 2010 decision by Spain's Constitutional Court to water down a 2006 statute giving the region more powers has added to pressure for secession.