Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

Catalonia's parliament declared independence from Spain on Friday in defiance of the Madrid government, which at the same time was preparing to impose direct rule over the region.

Although the declaration was largely symbolic, since it will not be accepted by Spain or the international community, the move, coupled with the impending vote in Madrid, took the country's worst political crisis in four decades to a new level.

Thousands of people who had gathered outside parliament in Barcelona cheered and danced after it passed the motion declaring an independent Catalan Republic.

The crowds had watched the voting process live on big screens, shouting "Liberty" in the Catalan language and singing traditional Catalan songs.

"I'm worried, I'm nervous like everybody. But freedom is never free," said Jaume Moline, 50, a musician.

Montserrat Rectoret, 61, a historian, said, "I am emotional because Catalonia has struggled for 40 years to be independent, and finally I can see it."

Spain's prime minister, Mariano Rajoy, immediately called for calm and said the rule of law would be restored.

Related: Spain Staging a 'Coup' in Catalonia, Parliament Officials Say

Minutes after the restive region declared its independence, the upper house of Spain's Parliament authorized Rajoy's government to rule Catalonia directly from Madrid.

The Spanish government will hold a special cabinet meeting at 6 p.m. local time (12 p.m. ET) to adopt the first measures to govern Catalonia.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

This could include firing the Barcelona government and assuming direct supervision of Catalan police forces.

"Spain is a serious country and a great nation and we will not tolerate that a few people try liquidate our constitution," Rajoy told journalists.

The U.S. State Department supported Spain in its efforts to keep the country stitched together.

"The United States enjoys a great friendship and an enduring partnership with our NATO Ally Spain," State Department spokeswoman Heather Nauert said. "Our two countries cooperate closely to advance our shared security and economic priorities. Catalonia is an integral part of Spain, and the United States supports the Spanish government’s constitutional measures to keep Spain strong and united."

The United Kingdom also provided a statement of support for Spain. But the Scottish government, which has a similar relationship with the U.K. as Catalonia does with Spain, emphasized the need for open talks.

"Now, more than ever, the priority of all those who consider themselves friends and allies of Spain should be to encourage a process of dialogue to find a way forward that respects democracy and the rule of law," said Fiona Hyslop, the Scottish Government Cabinet Secretary for Culture, Tourism and External Affairs. "The imposition of direct rule cannot be the solution and should be of concern to democrats everywhere."

Meanwhile, the main secessionist group in Catalonia, the Catalan National Assembly (ANC) called on civil servants not to follow orders from the Spanish government and respond with "peaceful resistance" instead.

The independence motion, which was boycotted by opposition parties, declared that Catalonia constituted an independent, sovereign and social democratic state, and called on other countries and institutions to recognize it as such.

It also said it wanted to open talks with Madrid on setting up the new republic.

"It is not going to be easy, it is not going to be free, it is not going to change in a day," Marta Rovira, a lawmaker with the Junts pel Si pro-independence alliance said in the debate leading up to the vote. "But there is no alternative to a process towards the Catalan Republic."

Catalan president Carles Puigdemont casts his vote for a motion on declaring independence from Spain Lluis Gene / AFP - Getty Images

After the debate, lawmakers from members of three main national parties — the People's Party, the Socialists and Ciudadanos — walked out.

Members of the pro-independence parties and the far-left Podemos then voted, 70-10, in a secret ballot aimed at hindering any attempt by the central government to lay criminal charges on them.

Spanish shares and bonds were sold off when the result of the vote was announced.

Catalan leader Carles Puigdemont left the chamber to shouts of "President!"

The crisis developed after an independence referendum on Oct. 1 was declared illegal by Madrid. Although it endorsed independence, it drew only a 43 percent turnout as Catalans who oppose independence largely boycotted it.

The crisis has split Catalonia and caused deep resentment around Spain — national flags now hang from many balconies in Madrid, the capital, in an expression of unity.

It has also prompted a flight of business from the wealthy northeastern region and alarmed European leaders who fear the crisis could fan separatist sentiment around the continent.

Catalonia is one of Spain's most prosperous regions and already has a high degree of autonomy. But it has a litany of historic grievances, exacerbated during the 1939-75 Franco dictatorship, when its culture and politics were suppressed.