Nicola Sturgeon has backed Catalonia's right to hold a referendum on independence, saying she is concerned about attempts to stop the vote.

Scotland's First Minister called for dialogue between the governments of Catalonia and Spain over the planned October 1 vote, which the Spanish government has declared illegal.

Ms Sturgeon said the Edinburgh Agreement, drawn up by the Scottish and UK Governments before the 2014 independence referendum in Scotland, could act as a template for others.

She said: "I think most people would agree that the situation in Catalonia is of concern.

"I hope that there will be dialogue between the Catalan and the Spanish governments to try to resolve the situation. That has got to be preferable to the sight of police officers seizing ballot papers and entering newspaper offices.

"It is of course entirely legitimate for Spain to oppose independence for Catalonia but what I think is of concern anywhere is for a state to seek to deny the right of a people to democratically express their will.

"The right of self determination is an important international principle and I hope very much that it will be respected in Catalonia and everywhere else.

"The Edinburgh Agreement is a shining example of two governments with diametrically opposed views on independence nevertheless coming together to agree a process that allowed the people to decide and I think that offers a template that can be used by others elsewhere in the world."

Ms Sturgeon made her comments as thousands gathered in Barcelona to demand the release of a dozen Catalan officials arrested in connection with the planned vote.

The demonstrators, who met at the gates of Catalonia's judicial body, answered a call by pro-independence civic groups to stage long-term street protests against the police surprise crackdown one day earlier.

Acting on a judge's orders, police seized 10 million ballot papers and arrested at least 12 people, mostly Catalan government officials, suspected of coordinating the referendum.

The arrests were the first involving Catalan officials since the campaign to hold an independence vote began in earnest in 2011.

Catalan vice-president Oriol Junqueras acknowledged that the crackdown had disrupted the referendum plans.

"It's evident that we won't be able to vote like we have done in the past," Mr Junqueras told broadcaster TV3.

Even so, he remained confident there will be a large turnout of Catalans on October 1, whatever form the vote takes.

Pro-independence leaders have insisted the ballot will go ahead despite the obstacles.

The Catalan National Assembly, a driving force behind the secession movement, urged people to gather at noon outside the region's justice tribunal and bring tents if needed.

By midday, the protesting crowds filled a square the size of two football pitches and erupted in slogans chanting "We will vote!" and "Hello democracy".

Many wrapped themselves in the "estelada" flag, which has become a symbol of those in favour of an independent Catalan republic, and some climbed lampposts to get a better view.

"We will be here, peacefully but present, until all of the arrested walk out free," the Assembly's president Jordi Sanchez told the cheering crowds.

The regional police force cordoned off the area, and live video streaming from the ground showed people angrily whistling and jeering at a police officer who became entangled with a protester.

There were no immediate reports of other major incidents, but the atmosphere was a mixture of the festive and the tense.

"Our motto is that we are not afraid," said Malena Palau, a 21-year-old student participating in the gathering.

"We want to vote because we have the right to decide, regardless of what we vote."

Spain's prime minister Mariano Rajoy has warned Catalan leaders of "greater harm" if they don't call off the referendum bid.

Catalonia represents a fifth of Spain's 1.1-trillion-euro economy and enjoys wide self-government, although key areas such as infrastructure and taxes are in the hands of central authorities.

The region has about 5.5 million eligible voters.

Polls consistently show the region's inhabitants favour holding a referendum but are roughly evenly divided over independence from Spain.