Catalonia's parliament voted on Friday to declare independence from Spain and proclaim a republic, just as Madrid is poised to impose direct rule on the semi-autonomous region to stop it in its tracks.

A motion declaring independence was approved with 70 votes in favour, 10 against and two abstentions, with Catalan opposition MPs walking out of the 135-seat chamber before the vote in protest at a declaration unlikely to be given official recognition by Madrid and abroad.

Tens of thousands of independence supporters massed near the Catalan parliament cheered with joy after lawmakers' vote.

Watching proceedings in parliament on two large screens, they clapped and shouted “independence” in Catalan before singing the regional hymn, many raising their fists.

Spanish Prime Minister Mariano Rajoy to “restore legality” in Catalonia after the regional parliament declared independence.

“I ask all Spaniards to remain calm. The rule of law will restore legality in Catalonia,” he wrote in a Twitter message immediately after the Catalan assembly voted in favour of declaring independence from Spain.

The wealthy region's drive to break away from Spain has unleashed the country's worst political crisis in a generation.

After staging a banned referendum on October 1, in which separatists said 90 per cent of people voted for secession, Catalan president Carles Puigdemont had said he had accepted a “mandate for Catalonia to become an independent state”.