By the Associated Press

BARCELONA, Spain— Masses of flag-waving demonstrators demanding Catalonia’s independence and the release from prison of separatist leaders jammed downtown Barcelona on Friday as the northeastern Spanish region endured its fifth straight night of unrest.

Chaotic scenes of violence erupted after more than a half million protesters, including families with children, marched in the Catalan capital, according to local police. Many were clad in pro-independence ‘estelada’ flags and shouted “Independence!” and “Freedom for political prisoners!”

Some of them had walked for three days in five massive “freedom marches” from towns across the northeastern Spanish region. They converged on Barcelona, a city of 1.6 million people, and joined students and workers who also took to the streets during a 24-hour general strike.

But at night, police resorted again to rubber bullets and, for the first time this week, to tear gas and water cannons to repel masked youths hurling cobblestones and flammable bottles, building barricades and setting dozens of bonfires with large garbage bins.

Around 400 people, roughly half of them police officers, have been injured according to regional and central authorities, and 128 arrested since separatist sentiment surged on Monday, when the Supreme Court sentenced to lengthy prison terms nine separatist politicians and activists. The nine had led a 2017 push for independence that triggered Spain’s deepest political crisis in decades.

On Friday, the huge displays of support were mostly peaceful, but protesters and police battled over the control of Barcelona’s center after protesters circled the gates of the national police’s headquarters. As clashes with police escalated, the chaos spread to other areas of the Catalan capital.

Albert Ramón, a 43-year-old public servant joining one of the rallies in the northern city of Girona, said the convictions — including fines for three more separatists — had soured the political climate.

“These verdicts violate fundamental rights and hence people are reacting,” Ramón said.

The separatist movement is proud of its history of mostly peaceful campaigning. Officials have accused a relatively small number of agitators of provoking the recent riots.

Spanish authorities suspect a secretive new group called Tsunami Democratic is using encrypted messages to orchestrate some of the attacks, which have included torched cars and burning barricades in the streets.

The group appeared on Sept. 2 and in just over six weeks has gained nearly 340,000 followers on its main channel in Telegram, a messaging app.

A National Court judge on Friday ordered the closure of websites linked to the group.

Rights group Amnesty International called on “all authorities” to refrain from contributing to the escalation of tensions in the streets and to respond “proportionally” to outbreaks of violence.

The group said in a statement that it had observed “various cases” of “excessive” use of police force, “including inappropriate and unjustified use of batons and other defensive equipment against people who posed no risk.”

But the interim interior minister, Fernando Grande-Marlaska, defended the police action as “proportionate” and warned Catalan separatists that Spain will apply the criminal code “with all its force,” threatening them with prison terms of up to six years.

Tourists also felt the turmoil. At least two large cruise operators diverted their ships to other ports, and those which had already docked in the port of Barcelona cancelled their passengers’ excursions to the city. Architect Antoni Gaudí’s modernist Sagrada Familia also closed its doors due to a protest blocking access to the basilica.

Naoya Suzuki, a 34-year-old tourist from Japan, complained about the disruptions to “people who have nothing to do with Spain.”

“I’ve had a look at the news and I can just about understand why they are angry, but not why are they are doing all this and stopping the sightseeing of tourists,” he said.

Dozens of flights into and out of the region were canceled due to the strike called by pro-independence unions. Picketers also blocked roads to the border with France and elsewhere, sometimes with burning tires.

Commuter and long-distance train services were significantly reduced, and many shops and factories didn’t open for business.

Spain’s interim prime minister, Pedro Sánchez, said authorities would prosecute radicals who rioted this week while ensuring that peaceful protests can continue.

“Those who break the law have to answer for their deeds sooner or later,” Sánchez told a press conference in Brussels, where he was attending a European Union summit.

Sánchez faces a general election in less than a month, and the tensions in Catalonia are a test of his political skills.

The former head of the Catalan government, Carles Puigdemont, on Friday avoided being jailed after he voluntarily testified before Belgian judicial authorities over a new warrant that Spain issued this week following the Supreme Court sentences. He is also wanted for his part in the 2017 independence bid.

The Belgian judge ordered his release without bail but instructed him to remain in Belgium while awaiting an Oct. 29 extradition hearing, the Belgian prosecutor’s office said in a statement.

Instability in Catalonia led to the postponement of next week’s marquee soccer match between Barcelona and Real Madrid. The Spanish soccer federation said the game was being moved to avoid overlap with a large separatist rally, as officials fear more violence.