SABADELL, Spain — The results of a controversial and chaotic referendum in the Catalonia region of northeast Spain on Sunday showed landslide support for independence for the restive but affluent area, a lopsided vote sure to be vigorously challenged by the constitutional court and central government in Madrid as illegitimate and illegal.

According to the Catalan government, 90 percent of the ballots cast were for independence – with 2,020,144 voting yes and 176,566 no.

Minutes after the first few thousand votes were posted, the regional president and leading secessionist, Carles Puigdemont, appeared on stage to announce that Catalonia had won “the right to independence” and called on Europe to support its split from Spain.

But nothing about the vote was regular – or orderly, transparent or peaceful. Images of police beating voters in stylish, cosmopolitan Barcelona fueled a widespread perception that Europe, in particular, and the West, in general – far from cheering on the breakup of Spain – face yet more tensions and dislocation.

And it is far from clear that Catalonia is any closer to independence. The vote left the region and nation deeply divided.

In a television address late Sunday, Spanish Prime Minister Mariano Rajoy said there was no real independence vote in Catalonia. He said a majority of the residents of the region had not even showed up at the polls.

Over the weekend, boisterous activist-voters had brought their children into schools to defend the polling stations deemed illegal by the central government in Madrid.

Soon after the polls opened, Spanish riot police smashed into the voting centers, their raids caught on mobile phone cameras that showed them whipping ordinary citizens with rubber truncheons and dragging them away by their hair.

The plebiscite produced anxiety and shock across Europe – where many condemned the violence by the police but also worried that Catalan secessionists were violating the constitution.

The secessionists said Spain’s heavy-handed attempt to snuff out the referendum stirred memories of the county’s dark decades of dictatorship.

Barcelona Mayor Ada Colau called the day’s violence between police and citizens “a rupture” in society.

Jordi Turull, the spokesman for the Catalonia regional government, described Spain’s use of police to suppress the vote as “the shame of Europe.”

But many in Spain saw a manipulative propaganda play by secessionists to stage a one-sided referendum designed to produce a yes vote no matter what.

“This was a sad day,” said Ines Arrimadas, a member of a center-right party in Catalonia who opposed the vote. “It was crazy to hold this referendum.”

She told Catalonia’s public broadcaster, which is staunchly pro-secession, that “on this TV broadcast you will believe the result, but no one on the outside will.”

Spain’s foreign minister, Alfonso Dastis, called the day’s violence “unpleasant” but “proportional.”

Yet the portrayal of the day’s events could not have been worse for the central government. Although Madrid might have had the Spanish constitution on its side, the images being blasted around the world showed peaceful citizens being dragged away from the ballot boxes by helmeted police dressed all in black.

The vote in Catalonia was a mass act of civil disobedience, organized by the regional government but propelled by WhatsApp groups, encrypted messages and clandestine committees.

There were stirring moments of people power – and the activists who organized the vote were often two steps ahead of Madrid.

As the police forced their way through shouting crowds into the schoolhouses that served as polling stations, the organizers spirited away the ballots and hid them in the classrooms amid coloring books and crayons.

An hour after police drove away from one school in their big black vans, under a hail of insults, the ballot boxes reemerged and the voting recommenced.

The pattern was repeated again and again across hundreds of polling stations Sunday.

By late afternoon, the Catalan health ministry said 844 people had suffered minor injuries in brawls with police, who could be seen punching some demonstrators. The officers also fired scores of rubber bullets at crowds in Barcelona and other cities. Officials in Madrid said a dozen police officers had been injured.

The past two weeks have seen mass demonstrations and a high-risk game of cat-and-mouse, as the secessionists sought to carry out a vote that Madrid vowed it would stop.

As the central government shut down websites promoting the referendum, new apps popped up to guide voters.

The Catalan government, dominated by breakaway leaders, said that despite police raids, more than 70 percent of the polling stations were open Sunday afternoon.

Meanwhile, the Spanish soccer league game between Barcelona and Las Palmas at the Camp Nou stadium went ahead without any fans in attendance.

Just before the polls opened, the Catalan regional government declared that any registered voter could vote anywhere – instead of having to visit their assigned polling station in their home towns. The voting lists, the regional government said, would be digital and not printed as usual for the polling officers to check against identification cards.

But there were problems right away with registering the voters – and the online system was balky. And this, among all the other irregularities, raised questions about the legitimacy of the vote.

Those who opposed the vote – especially the people who want to remain in Spain – scoffed that the Catalans were being allowed to vote as many times as they like.

Spain’s deputy prime minister, Soraya Sáenz de Santamaría, said in a news conference that the “absolute irresponsibility of the Catalan government has had to be dealt with by the professionalism of the state’s security forces. With firmness and proportionality, we have thrown into disarray the Catalan government’s plans. There hasn’t been a referendum nor the semblance of one. Nothing good will come of this.”