Barcelona, Spain (CNN)Spain dismissed Catalonia's president and Cabinet and dissolved its Parliament on Friday hours after lawmakers in the autonomous region defied Madrid and voted overwhelmingly to declare independence.

Spanish Prime Minister Mariano Rajoy called new elections and fired the Catalan police chief, as part of an unprecedented package of measures to seize control of the renegade administration in Barcelona.

He said said the moves were needed to restore legality, after a political and constitutional crisis that has gripped the country for months.

"In this moment, we need to be serene and careful, but we also need to have confidence that the state has the tools, backed by the law and reason, [to] peacefully and reasonably go back to legality and take away threats to democracy," he said.

Rajoy spoke hours after the Catalan Parliament voted by 70 to 10 to "form the Catalan Republic as an independent and sovereign state."

The day's dramatic and fast-moving events pushed Spain into uncharted territory, testing the limits of the constitution drawn up after the restoration of democracy in the 1970s.

Dramatic scenes in Barcelona

The stage was set when separatists in the Catalan Parliament tabled a motion to declare independence from Spain, arguing that a disputed referendum on October 1 gave them a mandate to split from Madrid.

Supporters of independence gather outside the Catalan Parliament in Barcelona.

After a heated debate, opposition parties walked out of the chamber before the vote, some leaving Catalan and Spanish flags on their empty seats.

Pro-independence crowds massed outside the Parliament cheered, jumped up and down, and waved flags, including the Catalan separatist "Estelada" flag, as the independence result was announced.