Polling stations closed in Catalonia after a tumultuous referendum on independence from Spain, marred by shocking scenes of violence towards voters by national police.

At one voting station in Barcelona, in the Joan Miro school, applause broke out after 8pm local time as it was announced that voting had ended. 

Spain's prime minister Mariano Rajoy, however, said in a televised address that no independence vote had taken place and said those organising the referendum had defied the rule of law.

He also praised police for their "firmness and serenity" following clashes in which Catalan health officials say 761 people were injured.

Volunteers at the Joan Miro school opened the plastic ballot boxes, turned them over and started sorting the ballots.

The "yes" pile was many times bigger than the "no" pile.

Joan Maria Pique, spokesman for Catalan president Carles Puigdemont, said polling stations were closing except at those where people were still waiting to vote.

Barcelona's mayor Ada Colau said earlier in the day that, as leader of the city, she wanted "an immediate end to police charges against the defenceless population".

Police baton-charged and fired rubber bullets to disperse crowds in Barcelona and other towns and cities.

Videos showed them beating people repeatedly as they try to confiscate ballots and ballot boxes.

In addition to the protesters and voters injured, Spain's Interior Ministry said 11 police officers have been injured fulfilling judicial orders to prevent the referendum on independence.

Earlier Catalan government spokesman Jordi Turull blamed the violence directly on Mr Rajoy and interior minister Juan Ignacio Zoido.

He said actions by Spanish National Police and Civil Guard forces were politically motivated and showed "a clear motivation to harm citizens".

Catalan international affairs director Raul Romeva said regional authorities would appeal to European bodies over Rajoy's government's alleged violations of human rights.

The officers fired rubber bullets while trying to clear protesters who were trying to prevent National Police cars from leaving after police confiscated ballot boxes from the voting centre.

Several people were injured during the scuffles outside Barcelona's Rius i Taule school, where some voters had cast ballots before police arrived.

Catalan officials said 38 people were treated for mostly minor injuries.

Manuel Condeminas, a 48-year-old IT manager who tried to block police from driving away with the ballot boxes, said agents had kicked them before using their batons and firing the projectiles.

Elsewhere, Civil Guard officers, wearing helmets and carrying shields, used a hammer to break the glass of the front door and a lock cutter to break into the Sant Julia de Ramis sports centre near the city of Girona.

At least one woman was injured outside the building and wheeled away on a stretcher by paramedics.

Clashes broke out less than an hour after polls opened, and not long before Puigdemont was expected to turn up to vote at the sports centre.

Polling station workers inside the building reacted peacefully and broke out into songs and chants challenging the officers' presence.

Mr Puigdemont was forced to vote in Cornella de Terri, near Girona.

The Spanish government and its security forces are trying to prevent voting in the independence referendum, which is backed by Catalan regional authorities. Spanish officials had said force would not be used, but that voting would not be allowed. Spain's Constitutional Court has suspended the vote.

Catalan leaders pledged to hold it anyway, promising to declare independence if the "yes" side wins, and have called on 5.3 million eligible voters to cast ballots.

Police had sealed off many voting centres in the hours before the vote to prevent their use. Others were filled with activists determined to hold their ground.

Spanish riot police forcefully removed a few hundred would-be voters from a polling station at a school in Barcelona.

Daniel Riano was inside when the police pushed aside a large group gathered outside the Estela school's front door.

The 54-year-old said that "we were waiting inside to vote when the National Police used force to enter, they used a mace to break in the glass door and they took everything".

He said that "one policeman put me in a headlock to drag me out, while I was holding my wife's hand. It was incredible. They didn't give any warning."

In an effort to overcome myriad obstacles, Catalan officials announced voters would be allowed to cast ballots in any location and could use ballots printed at home, rather than in designated polling stations as previously announced.

Turull also said a group of "academics and professionals" would serve as election observers.

The official electoral board appointed by the regional parliament was disbanded last week to avoid hefty fines by Spain's Constitutional Court.

Courts and police have been cracking down for days to halt the vote, confiscating 10 million paper ballots and arresting key officials involved in the preparations.

On Saturday, Civil Guard agents dismantled the technology to connect voting stations, count the votes and vote online, leading the Spanish government to announce that holding the referendum would be "impossible".

Puigdemont condemned the crackdown.

"Police brutality will shame forever the Spanish state," he said as crowds cheered.